tweepy
stable
  • Installation
  • Getting started
  • Authentication
  • Logging
  • Streaming

Twitter API v1.1 Reference

  • API
  • Stream
  • AsyncStream
  • Exceptions
  • Models
  • Pagination
  • Extended Tweets

Twitter API v2 Reference

  • Client
  • Response
  • StreamingClient
  • StreamResponse
  • StreamRule
  • AsyncClient
  • AsyncStreamingClient
  • Exceptions
  • Expansions and Fields
  • Models
  • Pagination

Meta

  • Changelog
  • Development
  • Examples
  • Frequently Asked Questions
tweepy
  • »
  • Pagination
  • Edit on GitHub

Pagination

class tweepy.Cursor(method, *args, **kwargs)

Cursor can be used to paginate for any API methods that support pagination

Parameters
  • method – API method to paginate for

  • args – Positional arguments to pass to method

  • kwargs – Keyword arguments to pass to method

items(limit=inf)

Retrieve the items in each page/request

Parameters

limit – Maximum number of items to iterate over

Returns

Iterator to iterate through items

Return type

ItemIterator

pages(limit=inf)

Retrieve the page for each request

Parameters

limit – Maximum number of pages to iterate over

Returns

Iterator to iterate through pages

Return type

CursorIterator or DMCursorIterator or IdIterator or NextIterator or PageIterator

Example

import tweepy

auth = tweepy.OAuth2AppHandler("Consumer Key here", "Consumer Secret here")
api = tweepy.API(auth)

for status in tweepy.Cursor(api.search_tweets, "Tweepy",
                            count=100).items(250):
    print(status.id)

for page in tweepy.Cursor(api.get_followers, screen_name="TwitterDev",
                            count=200).pages(5):
    print(len(page))
Previous Next

© Copyright 2009-2023, Joshua Roesslein. Revision 6ffc7348.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: stable
Versions
latest
stable
v4.13.0
v4.12.1
v4.12.0
v4.11.0
v4.10.1
v4.10.0
v4.9.0
v4.8.0
v4.7.0
v4.6.0
v4.5.0
v4.4.0
v4.3.0
v4.2.0
v4.1.0
v4.0.1
v4.0.0
v3.10.0
v3.9.0
v3.8.0
v3.7.0
v3.6.0
v3.5.0
v3.4.0
v3.3.0
v3.2.0
v3.1.0
v3.0.0
v2.3.0
Downloads
On Read the Docs
Project Home
Builds