An asynchronous wrapper around Stripe's official python library.
Project description
async-stripe
An asynchronous wrapper around Stripe's official python library.
How it works
async-stripe monkey-patches the stripe library and replaces the synchronous http request methods with asynchronous methods.
Monkey-patching allows us to avoid a complete rewrite and keep the usage api similar to the official library.
This doesn't use threads, but actual async coroutines and non-blocking http client to make requests.
Install
Install requires Python 3.6 or newer.
$ pip install async-stripe
Usage
The usage api is similar to Stripe's official library:
from async_stripe import stripe
stripe.api_key = '<stripe-secret-key>'
payment_intent = await stripe.PaymentIntent.create(amount=1000, currency='usd')
print(payment_intent.id)
/!\ Note: Since this library monkey-patches the actual stripe
library,
you should avoid using the two in the same process.
Once you import async_stripe
, the official stripe
library gets patched with
async methods and the original synchronous api won't be available.
Configuration
Please see stripe-python
's README file for configuring logging and other things.
Unsupported configurations:
async-stripe
aims to be a drop-in async replacement for stripe
. However,
there are a few things which are not yet supported:
- Custom http client: Currently, it's not possible to configure a
custom http client and Tornado's
AsyncHTTPClient
will be used by default. - Proxy: Connecting to api via a proxy is supported yet.
Development and Testing
When adding new features and monkey-patches, please add relevant tests and ensure that all the tests also pass.
For testing, first, install and run the stripe-mock
api server.
Next, install pytest
, pytest-mock
and pytest-asyncio
python packages in
your virtualenv.
Finally, run the tests like this:
$ pytest tests
# or run a specific test
$ pytests tests/api_resources/test_customer.py
$ pytests tests/api_resources/test_customer.py::TestCustomer
License
A lot of the code (especially tests) are copied with slight modifications from Stripe's official library. That code is licensed under MIT License.
Rest of the original code is licensed under BSD-3-Clause License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for async_stripe-2.57.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7713a6c46482440f510ac797f7fc40903a5547a9aedb98f9e2c7a96765d9f48 |
|
MD5 | 238275b82cd341551b08412fbf25e04c |
|
BLAKE2b-256 | 050a9e35f202ebbd2c63aa9b43ef151c6bca3e4a56b69110f28a2492320af7b8 |