- class tweepy.Stream(consumer_key, consumer_secret, access_token, access_token_secret, chunk_size=512, daemon=False, max_retries=inf, proxy=None, verify=True)
Filter realtime Tweets with Twitter API v1.1
New Twitter Developer Apps created on or after April 29, 2022 will not be able to gain access to v1.1 statuses/filter, the Twitter API v1.1 endpoint that
Streamuses. Twitter API v2 can be used instead with
バージョン 4.13 で変更: Removed
on_user_withheldmethods, as the Twitter API v1.1 statuses/sample endpoint and compliance messages on the Twitter API v1.1 statuses/filter endpoint have been retired
consumer_key (str) -- Twitter API Consumer Key
consumer_secret (str) -- Twitter API Consumer Secret
access_token (str) -- Twitter API Access Token
access_token_secret (str) -- Twitter API Access Token Secret
chunk_size (int) -- The default socket.read size. Default to 512, less than half the size of a Tweet so that it reads Tweets with the minimal latency of 2 reads per Tweet. Values higher than ~1kb will increase latency by waiting for more data to arrive but may also increase throughput by doing fewer socket read calls.
daemon (bool) -- Whether or not to use a daemon thread when using a thread to run the stream
max_retries (int) -- Max number of times to retry connecting the stream
proxy (str | None) -- URL of the proxy to use when connecting to the stream
- filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False, threaded=False)
Filter realtime Tweets
バージョン 4.9 で非推奨: The delivery of compliance messages through the Twitter API v1.1 endpoint this method uses has been deprecated, and they will stop being delivered beginning October 29, 2022. Twitter API v2 can be used instead with
Clientbatch compliance methods.
filter_level (str | None) --
Setting this parameter to one of none, low, or medium will set the minimum value of the filter_level Tweet attribute required to be included in the stream. The default value is none, which includes all available Tweets.
When displaying a stream of Tweets to end users (dashboards or live feeds at a presentation or conference, for example) it is suggested that you set this value to medium.
languages (list[str] | None) -- Setting this parameter to a comma-separated list of BCP 47 language identifiers corresponding to any of the languages listed on Twitter’s advanced search page will only return Tweets that have been detected as being written in the specified languages. For example, connecting with language=en will only stream Tweets detected to be in the English language.
stall_warnings (bool) -- Specifies whether stall warnings should be delivered
threaded (bool) -- Whether or not to use a thread to run the stream
TweepyException -- When the stream is already connected or when the number of location coordinates is not a multiple of 4
The thread if
threadedis set to
threading.Thread | None
This is called when raw data is received from the stream. This method handles sending the data to other methods based on the message type.
raw_data (JSON) -- The raw data from the stream
This is called when a status is received.
status (Status) -- The Status received
This is called when a disconnect message is received.
message (JSON) -- The disconnect message
This is called when a limit notice is received.
track (int) -- Total count of the number of undelivered Tweets since the connection was opened
This is called when a stall warning message is received.
warning (JSON) -- The stall warning
Disconnect the stream
This is called when the stream has been closed by Twitter.
response (requests.Response) -- The Response from Twitter
This is called after successfully connecting to the streaming API.
This is called when the stream connection errors or times out.
This is called when the stream has disconnected.
This is called when an unhandled exception occurs.
exception (Exception) -- The unhandled exception
This is called when a keep-alive signal is received.