Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for asyncio #732

Open
wrobell opened this issue May 18, 2016 · 20 comments
Open

Add support for asyncio #732

wrobell opened this issue May 18, 2016 · 20 comments
Labels
Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature
Milestone

Comments

@wrobell
Copy link

wrobell commented May 18, 2016

It would be great if Tweepy integrated with asyncio. For example, to get data using a stream we would use something like

stream = AsyncStream(auth_handler)
...
data = await stream.filter(track=['python', 'tweepy', 'asyncio'])  # or "yield from"
@thewillwilson

This comment has been minimized.

@likewhoa

This comment has been minimized.

@Harmon758 Harmon758 added the Improvement This is regarding an improvement to an existing feature label Apr 25, 2019
@Harmon758 Harmon758 added this to the 4.0 milestone Aug 3, 2019
@Harmon758
Copy link
Member

The blocking issue for this has been Python 2 support, and with #1253, I'd like to plan to integrate support for asyncio in v4.0, especially for streams.

@dhilst

This comment has been minimized.

@Harmon758 Harmon758 changed the title add support for asyncio Add support for asyncio Dec 27, 2020
@Harmon758 Harmon758 added the Feature This is regarding a new feature label Dec 28, 2020
@Harmon758
Copy link
Member

I've created an async-streaming branch and draft PR #1491 that adds support for asynchronous streaming with asyncio.
Any testing and/or feedback would be appreciated.

@Harmon758
Copy link
Member

The async-streaming branch / pull request #1491 should be complete now.
Any feedback or review would be appreciated.

@asiercampos

This comment has been minimized.

@Harmon758
Copy link
Member

The documentation for streaming can be found at https://docs.tweepy.org/en/v3.10.0/streaming_how_to.html for v3.10.
For the latest development version on the master branch, it can be found at https://docs.tweepy.org/en/latest/stream.html and https://docs.tweepy.org/en/latest/asyncstream.html.

AsyncStream is asynchronous. This means that AsyncStream.filter will not block, so that is as intended.

As for it not actually streaming, you need to have a running event loop for the task to execute. I don't think this will be changed, as adding handling for the event loop within AsyncStream.filter and AsyncStream.sample adds unnecessary complexity that is more likely to cause unexpected behavior than provide useful functionality. I'm not really sure what you mean by "with tweepy pro that needed it to be asynchronous" and what your use case is, but in place of the code you've shown as is, you can simply use a normal (non-asynchronous) Stream. Otherwise, it's not too complicated to manage the event loop yourself.

Also, once support for Python 3.6 is dropped and bd0b403 is reverted, this should raise a RuntimeError, saying "no running event loop".

For code block usage, see https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks.

@kenthegreat8

This comment has been minimized.

@Harmon758
Copy link
Member

Like I said, I'm not really sure what "tweepy pro" is referring to here.
If you're referring to the tweepy.asynchronous subpackage added with #1491, that's now been merged into the latest development version on the master branch.

@Harmon758
Copy link
Member

I'm going to push non-streaming support for asyncio (for API and Client) back to a v4.x release.
I want to get v4.0 out already, as there's already a ton of changes, including support for Twitter API v2.

@Harmon758
Copy link
Member

v4.0.0 (#1666) has now been released with support for asynchronous streaming 🎉

@Harmon758 Harmon758 modified the milestones: 4.0, 4.1 Sep 25, 2021
@Harmon758
Copy link
Member

asynchronous.AsyncClient has been added with 0aadd53.

@Harmon758
Copy link
Member

asynchronous.AsyncStreamingClient has been added with 9051ba6.

@JDJGInc
Copy link

JDJGInc commented May 19, 2022

👍

@Harmon758
Copy link
Member

v4.10.0 (#1901) has now been released with asynchronous support for Twitter API v2 🎉

I don't have a clear plan for an asynchronous version of API yet, as the non-asynchronous version still uses a good deal of legacy cruft (mainly in the way of models) that I'd prefer not to have to mimic in a new interface.

@JDJGInc
Copy link

JDJGInc commented May 20, 2022

it seems to work from where I have used it, thank you for having it :)

@BjoernPetersen
Copy link

Is there already a Paginator class to use with the AsyncClient? I guess that may deserve a separate issue...

@Harmon758
Copy link
Member

asynchronous.AsyncPaginator has been added with 33e444a.

@ghost
Copy link

ghost commented Nov 29, 2022

Is there still a plan around an Async API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature This is regarding a new feature Improvement This is regarding an improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

9 participants