-
Notifications
You must be signed in to change notification settings - Fork 432
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
Feature request: asyncio support #327
Comments
Hi Stephen, I really like this idea! The bad news is that I don't know if we're going to be able to do it in the immediate future :/ The library is currently primarily targets Python 2, and we use "2to3" for compatibility across both major versions. I just ran some analytics against the Stripe platform, and requests from Python 2 outnumber requests from Python 3 by a full 10 to 1, so for the time being, this setup still makes sense for the project. It might be possible to invert the primary major version by using something like "3to2" instead, but I suspect that it might not support really fancy Python 3+ constructs like async/await. Also, for now, the asyncio docs seem to suggest avoiding the package if wide version support is necessary:
Given that Python's 2 to 3 chasm seems to be a problem that might never be solved, I suspect that a more plausible way to get this in would be start maintaining a separate Python 3 fork that can leverage the richer features of 3+. Unfortunately, I can't promise this anytime soon because we'd really need to ramp up out internal language teams to make it happen. Even so, I'm going to leave this open and tag it as "future", and hopefully it'll become tractable given a little more time. |
Any news on this ? |
@FranzPoize @brandur-stripe's comment above is still largely valid. While we no longer use 2to3, we still need to support Python 2 for the foreseeable future (more than half of Stripe's Python users are on 2.7), and we currently don't have the bandwidth to start a new Py3-only library. |
Just food for thought: one way to make asyncio-compatible code with python 2 support is to support Twisted :). |
Leaving a +1 on this issue to further raise awareness. Now that we are within 18 months of Python 2's end of lifecycle support, I imagine there will be an ever-increasing trend of production-ready |
Hi all, given Python 2's end of life in January 2020, is there any intention to add official support for async Python and await coroutines to the Stripe library in the near future? |
Hi @adeadman. We will likely keep supporting Python 2 for some time after the EOL deadline, depending on how quickly our userbase migrates to Python 3. That said, we're considering shipping a separate Python module |
That's great to hear, an officially maintained library would be preferable to us than contributing to an unofficial one. How do you collect statistics on the python version your userbase are running? I know we've been python 3 for the last 2 years. The risk is that people who are still running py2 may not even be aware of the end of life - would a deprecation notice be displayed either in their application logs or in the Stripe dashboard? |
Requests sent from our official client libraries include a At the moment, ~35% of stripe-python users are still running Python 2. It's slowly declining, and I'm hoping there will be a sharper decrease once we reach the EOL deadline 🤞
Yes! This is also something we've been talking about. There should be some form of notice in the dashboard to inform users and encourage them to upgrade sooner rather than later. |
Any updates on this issue? For us being able to send requests asynchronously is quite critical. Without support from the library one is forced to use ugly workarounds like running the stripe calls in a separate executor. |
Hi @rubik. As I mentioned in a previous message, we're leaning towards shipping a separate library (both because we'll probably need to support Python 2.7 for some time past the EOL, and because Python's async model does not make it easy to ship sync and async code side by side). No ETA yet, but I'll see if this is something we can prioritize this half. |
I understand the need to support people running legacy versions from a business perspective but it is disappointing that EOL software is preventing progress (this is not a criticism of stripe directly, more a general commentary on the 2-vs-3 situation). Running in its own thread executor is enough for my simple use case for now... thanks for the lib! |
@arlyon Thanks a lot for the feedback and we agree it'd be great to support this. The change is a pretty big paradigm change though and so doing a separate library makes more sense I think as we can also plan adding support for types and pinning to a specific API version. We're looking into this internally to see whether this is work we could prioritize this year! |
Any new updates since 5 months ago? |
@WardPearce No progress just yet unfortunately. We focused on doing code generation for stripe-dotnet which is now complete. We're now improving stripe-java, with hope to add the new client/service infrastructure to it first. While adding async support to stripe-python is something we want to do, it'll likely take a while before we get to it unfortunately. |
I got this 😎 |
I'm starting development over @ https://github.com/WardPearce/stripe3 Feel free to open some PRs or submit requests via issues. Pretty early stages development, development will start to speed up after the 13th. |
@WardPearce can I request that you keep #689 in mind if you're developing something from scratch? :) |
hmmm, i seem to have gotten most of this current lib working using the |
@part1cleth1ef I'd recommend talking to our support team for help instead: https://support.stripe.com/contact/email |
Hi, if anyone's interested, I've created an async wrapper for stripe: https://github.com/bhch/async-stripe. |
@remi-stripe nvm, i fixed it, it turned out that because i was using |
I've been busy working on like 3 other projects, I will eventually get my wrapper done. It will be completely different to the current design stripe uses. Aiming to be more developer friendly. Will be similar to my b2 wrapper https://github.com/WardPearce/backblaze |
between stripe, square, et. al, it seems this is going to take years for adoption - one of the primary difficulties in async for large cos. whom consume stripe et. al is the chicken in the egg problem: a handful of third party libraries support async, and you need all libraries to support async in order to have a seamless transition. thank you for the wrappers above - think this will be best and a separate github repo likely needed one place to start could also be to create an official rust api client w/ async & auto generate python wrappers |
If python 2 support could be removed from Personally I'd take the project on myself, but I've been busy recently & stripe is a massive API |
Any update? |
@richardm-stripe Thank you so much for adding this feature in the beta channel! This feature will be immensely helpful in my current project. I recently discovered that synchronous methods in our ASGI server are causing the server to be blocked (the event loop effectively stalls), so I decided to begin implementing From my implementation with Lmk if any of these assumptions I'm making are incorrect. These are issues I'm seeing in the diff between my current synchronous implementation and this new request. Unrelated - I'm excited for this PR of yours to land as well! And again, thank you for adding this into the official Stripe SDK 👍 |
Exciting to see that this is moving 😃 I tried it out, and unfortunately the single use of It would additionally be fantastic to run your tests against both backends, which |
Thank you @tsalpekar21 for trying out the beta! I've reproduced the "raw_request_async doesn't do retries or produce the correct errors" bug and have a fix in #1209. |
Thank you also @Zac-HD for trying out the beta, and for pointing out that HTTPX already introduces a dependency on anyio. I'm going to attempt something like this #1210 -- (we aren't going to officially register HTTPX or AnyIO as a dependency, but we'll check to see if it's there and use it if so), and I'm working on trying to set up the anyio test fixture. PRs are certainly welcome, but I am actively working on this project again, so the best way you can help is to continue providing feedback and guidance in comments on this PR, as you have been. |
As a general update, I'm aiming for #1171 to be in next week's beta release, so it will be possible to try out async with the "real" SDK methods, instead of just |
Sounds great! I do think it's important to run some integration tests using Trio though - the At that point I'd personally accept a hard dependency on |
Hello async awaiters! Recently released to betahttps://github.com/stripe/stripe-python/releases/tag/v8.2.0b1 contains several async-related updates to the async support in the beta channel, notably code-generated definitions for resource methods -- i.e. now you can What's still pending:
Discussion questions / How you can help
Thanks everybody for your patience and willingness to provide feedback so far! |
(I work with Zac) we updated to the beta and it has been running smoothly! Thanks for working on this. |
At least for https://gist.github.com/AstreaTSS/b87fc66a68f48e95a59dd951b49f9cdc (Note that I've only done basic tests on it, though I will note one thing - the client should be initialized inside of a task, IE in an async startup event function. This isn't exclusive to EDIT: Edited for |
I started trying out some of the async support last week, and I ran into an issue when trying to run tests with Python version: 3.10.11 Code to reproduce:
Stack trace:
The function causing the error appears to be the second test function. If I move the two stripe statements to the same test, it works as expected. Hope that helps! |
It's great to see async support being added to the official Python SDK. I for one would like to have it include a built in aiohttp client implementation, though. |
Hello @Padge91, thanks for describing your experiences with httpx_client = httpx.AsyncClient()
class TestBug(unittest.IsolatedAsyncioTestCase):
async def test_bug_a(self):
await httpx_client.get(...))
async def test_bug_b(self):
await httpx_client.get(...)) What you can do to avoid it is async def asyncSetUp(self):
# This works in the latest beta release
stripe.default_http_client = stripe.HTTPXClient()
async def test_bug_a(self):
await stripe.Customer.create_async()
async def test_bug_b(self):
await stripe.Customer.create_async() Did you have anything particular in mind to make this experience nicer? Something I learned is that this is caused by HTTPX's connection pool. If you httpx_client = httpx.AsyncClient()
class TestBug(unittest.IsolatedAsyncioTestCase):
async def test_bug_a(self):
await httpx_client.get(..., headers={"Connection": "close"}))
async def test_bug_b(self):
await httpx_client.get(..., headers={"Connection": "close"})) it won't use the connection pool, and this test will actually succeed. Connection pooling is useful because it helps re-use resources across multiple requests made with the same client, but something I'm considering is disabling connection pooling by default in the automatically populated |
Hello async awaiters, UpdatesThe
This latter change you can probably address by making changes after these patterns. - stripe.default_http_client_async = ...`
+ stripe.default_http_client = ...
- class MyCustomAsyncHttpClient(stripe.HTTPClientAsync):
- ...
+ class MyCustomAsyncHttpClient(stripe.HTTPClient):
+ ... Although if you are making synchronous requests in your integration still and want to leave those unchanged and don't want to direct those to the same http client as your asynchronous requests, you might have to do a little more work, see the PR description and the "async_fallback_client" option. What's next?
How you can help
Thank you again to everybody on this thread for your patience, the excellent feedback so far, and helping develop this feature! |
And alongside all of that, thanks! We really appreciate the thought and care going into this, and it shows 🙂 |
@richardm-stripe Thanks for response (and all your work on this), your workaround should be sufficient. I don't see a simpler way at this moment. I must have missed #2959 in my initial research, as it seems to be this exact issue.
That seems reasonable to me. Otherwise, as the referenced issue in httpx suggests, repeated |
UpdatesJust cut a new release that
With this release, we are considering async support to be "feature complete". We're leaving it in the beta branch for awhile, because we still want to reserve the right to change the interface breakingly if a problem is discovered, but things should be completely ready for use. So if something is missing that prevents you from migrating, this isn't just "the feature is incomplete", it's probably a bug. Please continue to leave feedback. How you can help
|
@richardm-stripe: Thanks for adding aiohttp support! However, I've found that I encounter the following error when I try to use
When I saw the SSL cert verification error, I tried again with As an aside, I think that, for parity with the other if self._verify_ssl_certs:
ssl_context = ssl.create_default_context(cafile=stripe.ca_bundle_path)
kwargs["connector"] = TCPConnector(ssl=ssl_context)
else:
kwargs["connector"] = TCPConnector(verify_ssl=False) |
Thank you for the report and investigation @OldSneerJaw! 🤦 really jumped the gun on announcing "feature complete". |
@richardm-stripe: BTW, I submitted a potential fix that should make it so that |
We released the async support to the stable channel today in https://github.com/stripe/stripe-python/releases/tag/v8.10.0 (#1288). I am closing out the issue as the feature is now available, but please feel free to open new issues to leave feedback or any bug reports. |
Hi folks,
I was wondering what it would take to get this library to support asyncio. This would mean it would be possible to use Python 3.5+ async/await coroutines with a number of async frameworks.
Looking at the code it would be possible to create a new Http Client with say aiohttp, but it looks like the code would need to be modified in other places in order to support it.
Has the Stripe team considered async support?
The text was updated successfully, but these errors were encountered: