AsyncStreamingClient
- class tweepy.asynchronous.AsyncStreamingClient(bearer_token, *, return_type=Response, wait_on_rate_limit=False, max_retries=inf, proxy=None)
Stream realtime Tweets asynchronously with Twitter API v2
Nowe w wersji 4.10.
- Parametry
bearer_token (str) – Twitter API Bearer Token
return_type (type[dict | requests.Response | Response]) – Type to return from requests to the API
wait_on_rate_limit (bool) – Whether or not to wait before retrying when a rate limit is encountered. This applies to requests besides those that connect to a stream (see
max_retries
).max_retries (int | None) – Number of times to attempt to (re)connect the stream.
proxy (str | None) – URL of the proxy to use when connecting to the stream
- session
Aiohttp client session used to connect to the API
- Type
- task
The task running the stream
- Type
- async add_rules(add, *, dry_run)
This function is a coroutine.
Add rules to filtered stream.
- Parametry
add (list[StreamRule] | StreamRule) – Specifies the operation you want to perform on the rules.
dry_run (bool) – Set to true to test the syntax of your rule without submitting it. This is useful if you want to check the syntax of a rule before removing one or more of your existing rules.
- Zwraca
- Typ zwracany
References
- async delete_rules(ids, *, dry_run)
This function is a coroutine.
Delete rules from filtered stream.
- Parametry
ids (int | str | list[int | str | StreamRule] | StreamRule) – Array of rule IDs, each one representing a rule already active in your stream. IDs must be submitted as strings.
dry_run (bool) – Set to true to test the syntax of your rule without submitting it. This is useful if you want to check the syntax of a rule before removing one or more of your existing rules.
- Zwraca
- Typ zwracany
References
- filter(*, backfill_minutes=None, expansions=None, media_fields=None, place_fields=None, poll_fields=None, tweet_fields=None, user_fields=None)
Streams Tweets in real-time based on a specific set of filter rules.
If you are using the academic research product track, you can connect up to two redundant connections to maximize your streaming up-time.
The Tweets returned by this endpoint count towards the Project-level Tweet cap.
- Parametry
backfill_minutes (int | None) –
By passing this parameter, you can request up to five (5) minutes worth of streaming data that you might have missed during a disconnection to be delivered to you upon reconnection. The backfilled Tweets will automatically flow through the reconnected stream, with older Tweets generally being delivered before any newly matching Tweets. You must include a whole number between 1 and 5 as the value to this parameter.
This feature will deliver duplicate Tweets, meaning that if you were disconnected for 90 seconds, and you requested two minutes of backfill, you will receive 30 seconds worth of duplicate Tweets. Due to this, you should make sure your system is tolerant of duplicate data.
This feature is currently only available to the Academic Research product track.
expansions (list[str] | str) – expansions
media_fields (list[str] | str) – media_fields
place_fields (list[str] | str) – place_fields
poll_fields (list[str] | str) – poll_fields
tweet_fields (list[str] | str) – tweet_fields
user_fields (list[str] | str) – user_fields
- Wyrzuca
TweepyException – When the stream is already connected
- Zwraca
The task running the stream
- Typ zwracany
References
- async get_rules(*, ids)
This function is a coroutine.
Return a list of rules currently active on the streaming endpoint, either as a list or individually.
- Parametry
ids (list[str] | str) – Comma-separated list of rule IDs. If omitted, all rules are returned.
- Zwraca
- Typ zwracany
References
- sample(*, backfill_minutes=None, expansions=None, media_fields=None, place_fields=None, poll_fields=None, tweet_fields=None, user_fields=None)
Streams about 1% of all Tweets in real-time.
If you are using the academic research product track, you can connect up to two redundant connections to maximize your streaming up-time.
- Parametry
backfill_minutes (int | None) –
By passing this parameter, you can request up to five (5) minutes worth of streaming data that you might have missed during a disconnection to be delivered to you upon reconnection. The backfilled Tweets will automatically flow through the reconnected stream, with older Tweets generally being delivered before any newly matching Tweets. You must include a whole number between 1 and 5 as the value to this parameter.
This feature will deliver duplicate Tweets, meaning that if you were disconnected for 90 seconds, and you requested two minutes of backfill, you will receive 30 seconds worth of duplicate Tweets. Due to this, you should make sure your system is tolerant of duplicate data.
This feature is currently only available to the Academic Research product track.
expansions (list[str] | str) – expansions
media_fields (list[str] | str) – media_fields
place_fields (list[str] | str) – place_fields
poll_fields (list[str] | str) – poll_fields
tweet_fields (list[str] | str) – tweet_fields
user_fields (list[str] | str) – user_fields
- Wyrzuca
TweepyException – When the stream is already connected
- Zwraca
The task running the stream
- Typ zwracany
References
- async on_data(raw_data)
This function is a coroutine.
This is called when raw data is received from the stream. This method handles sending the data to other methods.
- Parametry
raw_data (JSON) – The raw data from the stream
References
- async on_tweet(tweet)
This function is a coroutine.
This is called when a Tweet is received.
- Parametry
tweet (Tweet) – The Tweet received
- async on_includes(includes)
This function is a coroutine.
This is called when includes are received.
- Parametry
includes (dict) – The includes received
- async on_errors(errors)
This function is a coroutine.
This is called when errors are received.
- Parametry
errors (dict) – The errors received
- async on_matching_rules(matching_rules)
This function is a coroutine.
This is called when matching rules are received.
- Parametry
matching_rules (list[StreamRule]) – The matching rules received
- async on_response(response)
This function is a coroutine.
This is called when a response is received.
- Parametry
response (StreamResponse) – The response received
- disconnect()
Disconnect the stream
- async on_closed(resp)
This function is a coroutine.
This is called when the stream has been closed by Twitter.
- Parametry
response (aiohttp.ClientResponse) – The response from Twitter
- async on_connect()
This function is a coroutine.
This is called after successfully connecting to the streaming API.
- async on_connection_error()
This function is a coroutine.
This is called when the stream connection errors or times out.
- async on_disconnect()
This function is a coroutine.
This is called when the stream has disconnected.
- async on_exception(exception)
This function is a coroutine.
This is called when an unhandled exception occurs.
- Parametry
exception (Exception) – The unhandled exception