8000 Beta: document async support in README.md (#1256) · stripe/stripe-python@699bd36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 699bd36

Browse files
Beta: document async support in README.md (#1256)
1 parent a0d85ca commit 699bd36

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,54 @@ response = stripe.raw_request(
277277
deserialized_resp = stripe.deserialize(response)
278278
```
279279
280+
### Async
281+
282+
Asynchronous versions of request-making methods are available by suffixing the method name
283+
with `_async`.
284+
285+
```python
286+
# With StripeClient
287+
client = StripeClient("sk_test_...")
288+
customer = await client.customers.retrieve_async("cus_xyz")
289+
290+
# With global client
291+
stripe.api_key = "sk_test_..."
292+
customer = await stripe.Customer.retrieve_async("cus_xyz")
293+
294+
# .auto_paging_iter() implements both AsyncIterable and Iterable
295+
async for c in await stripe.Customer.list_async().auto_paging_iter():
296+
...
297+
```
298+
299+
There is no `.save_async` as `.save` is [deprecated since stripe-python v5](https://github.com/stripe/stripe-python/wiki/Migration-guide-for-v5#deprecated). Please migrate to `.modify_async`.
300+
301+
The default HTTP client uses `requests` for making synchronous requests but
302+
`httpx` for making async requests. If you're migrating to async, we recommend
303+
you to explicitly initialize your own http client and pass it to StripeClient
304+
or set it as the global default.
305+
306+
```python
307+
# By default, an explicitly initialized HTTPXClient will raise an exception if you
308+
# attempt to call a sync method. If you intend to only use async, this is useful to
309+
# make sure you don't unintentionally make a synchronous request.
310+
my_http_client = stripe.HTTPXClient()
311+
312+
# If you want to use httpx to make sync requests, you can disable this
313+
# behavior.
314+
my_http_client = stripe.HTTPXClient(allow_sync_requests=True)
315+
316+
# aiohttp is also available (does not support sync requests)
317+
my_http_client = stripe.AIOHTTPClient()
318+
319+
# With StripeClient
320+
client = StripeClient("sk_test_...", http_client=my_http_client)
321+
322+
# With the global client
323+
stripe.default_http_client = my_http_client
324+
```
325+
326+
You can also subclass `stripe.HTTPClient` and provide your own instance.
327+
280328
## Support
281329

282330
New features and bug fixes are released on the latest major version of the Stripe Python library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

0 commit comments

Comments
 (0)
0