Skip to main content

async-stripe

Build Status

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. Hence, the performance is much better than other wrapper libraries which use threading.

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 not supported yet.

Development and Testing

When adding new features and monkey-patches, please add relevant tests and ensure that all the tests also pass.

In most cases, you shouldn't need to write the tests yourself: you can just copy-paste the tests form the original stripe library and change the synchronous methods to asynchronous methods.

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
$ pytest tests/api_resources/test_customer.py
$ pytest 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.

Release files for async-stripe 6.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-stripe 6.1.0
File Size Uploaded
async_stripe-6.1.0.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-stripe 6.1.0
File Interpreter ABI Platform
async_stripe-6.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.1 kB

Release files / async_stripe-6.1.0.tar.gz

Download URL async_stripe-6.1.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e141beda440809e1f05638dc0bb4aec31da5eb1ddfd791b215ac42202940a086
BLAKE2b-256 checksum
How to use checksums
9d27a634ef4b7fb6e28027c69d61c1b8862c0071bab650bbcb96d36294264c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.2 Linux/6.2.0-1015-azure

Release files / async_stripe-6.1.0-py3-none-any.whl

Download URL async_stripe-6.1.0-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3662e05c471565ec36aad7fa3acd4fae34598a6ea00a03f34cfc038d3ad1af19
BLAKE2b-256 checksum
How to use checksums
1af9ad205b82ce1e7ada4035d979ba703530f90d47e498afdeb37685bbef693e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.2 Linux/6.2.0-1015-azure

Release history Release notifications | RSS feed

This release

6.1.0 This release

2 release files

6.0.0

2 release files

5.5.0

2 release files

5.4.0

2 release files

5.3.0

2 release files

5.2.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.76.0

2 release files

2.75.0

2 release files

2.74.0

2 release files

2.73.0

2 release files

2.72.0

2 release files

2.71.0

2 release files

2.66.0

2 release files

2.65.0

2 release files

2.63.0

2 release files

2.62.0

2 release files

2.61.0

2 release files

2.60.0

2 release files

2.59.1

2 release files

2.59.0

2 release files

1.0.0

2 release files

0.1.2

1 release file

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page