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

Beta: raw_request_async with HTTPX #1165

Merged
merged 18 commits into from
Jan 4, 2024
Merged

Beta: raw_request_async with HTTPX #1165

merged 18 commits into from
Jan 4, 2024

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Dec 8, 2023

Summary

Adds async infrastructure and stripe.raw_request_async to the beta channel.

Details

Additions:

  • stripe.raw_request_async - Gives a small surface area so that we can test async "end to end". We will codegen async methods for each API method in a follow-up.
  • stripe.HTTPClientAsync - Defines the "interface" for defining an async http client.
  • stripe.HTTPXClient - Default implementation of stripe.HTTPClientAsync. I picked httpx somewhat arbitrarily. It happens to be what openai used (a few months ago, openai-python was a fork of stripe-python with added async support, but this is no longer the case). We can add more or different defaults.
  • stripe.default_http_client_async - A place for a user to set a custom async client
    (either a custom stripe.HTTPXClient or they can implement HTTPClientAsync.
  • ApiRequestor.request_async, ApiRequestor.request_stream_async, ApiRequestor.request_raw_async - Infrastructure methods that lie between raw_request and http_client.

Notes:

  • I omitted the ability to pass http_client_async into an ApiRequestor. You have to use the global http client. Mostly this is in the name of minimalism. Shouldn't be needed after StripeClient lands.
  • The stripe.new_default_http_client_async function exists but it is not exported publicly. It doesn't make too much sense to add because there's only one baked-in HTTPClientAsync: HTTPX, so you might as well just construct a stripe.HTTPXClient.
  • Since there are two http clients, users who want to use both sync and async interfaces might need to specify options such as verify_ssl_certs and proxy twice. In theory we could try and unify the interface for setting these settings on the global client, but I don't think this is an important enough use case to justify the additional complication.

@richardm-stripe richardm-stripe force-pushed the richardm-async-wip branch 2 times, most recently from c27a56c to 288a34a Compare December 8, 2023 23:42
flake8_stripe/flake8_stripe.py Outdated Show resolved Hide resolved
stripe/_api_requestor.py Outdated Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
@richardm-stripe
Copy link
Contributor Author

Ok, this should be ready again. The git history got messy, but since you last looked I

@richardm-stripe richardm-stripe requested review from pakrym-stripe and removed request for pakrym-stripe January 4, 2024 15:23
Copy link
Contributor

@pakrym-stripe pakrym-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions about http client tests

@richardm-stripe richardm-stripe merged commit be61235 into beta Jan 4, 2024
15 checks passed
@richardm-stripe richardm-stripe deleted the richardm-async-wip branch January 26, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants