Registry / payments / async-stripe

async-stripe

JSON →
library6.1.0pypypi✓ verified 22d ago

async-stripe is an asynchronous wrapper around Stripe's official `stripe-python` library, allowing its use in `asyncio` environments without blocking the event loop. It mirrors the `stripe-python` API, making all methods awaitable. The current version is 6.1.0, and its release cadence closely follows major and minor updates of `stripe-python`.

pip install async-stripe
INSTALL
IMPORT
SIG · ASYNC-STRIPE
A
async-stripe
paymentspythonv6.1.0
Install
2.7s avg
Import
692ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.724s · 26.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.660s · 27MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

StripeClient
from async_stripe import stripe
from async_stripe import StripeClient

Initialize the `StripeClient` with your API key using an `async with` block, then perform API operations using `await`. Ensure `STRIPE_API_KEY` is set in your environment.

import asyncio import os from async_stripe import StripeClient async def main(): # It's recommended to load API key from environment variables api_key = os.environ.get('STRIPE_API_KEY', 'sk_test_...') # Use async with for proper resource management async with StripeClient(api_key=api_key) as stripe: try: customer = await stripe.Customer.create(email="test_user@example.com", description="Test Customer") print(f"Customer created: {customer.id}") # Example: Retrieve the customer retrieved_customer = await stripe.Customer.retrieve(customer.id) print(f"Retrieved customer email: {retrieved_customer.email}") except Exception as e: print(f"An error occurred: {e}") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingMajor versions of `async-stripe` align with major versions of `stripe-python`. Upgrading `async-stripe` may introduce breaking changes inherited from `stripe-python`. Always review `stripe-python`'s changelog when upgrading `async-stripe`'s major version.
fix
Consult the `stripe-python` changelog and `async-stripe` release notes. Update API call syntax and object structures as required by the upstream library.
affects: All major version upgrades (e.g., v5.x to v6.x)
gotchaAll Stripe API calls via `StripeClient` methods are coroutines and *must* be `await`ed. Forgetting `await` will result in a coroutine object being returned, not the actual API response, leading to silent failures or incorrect logic downstream.
fix
Ensure every call to `stripe.Resource.method(...)` is prefixed with `await`, e.g., `customer = await stripe.Customer.create(...)`.
affects: All versions
gotchaAvoid setting `stripe.api_key = '...'` globally in `asyncio` applications. This synchronous method is not thread-safe or async-safe and can lead to race conditions or incorrect API key usage in concurrent requests.
fix
Always initialize `async_stripe.StripeClient` with the `api_key` argument, preferably using an `async with` block for proper context management: `async with StripeClient(api_key=your_key) as stripe:`.
affects: All versions
gotchaDo not attempt to mix direct `stripe` module imports (e.g., `from stripe import Customer`) with `async_stripe.StripeClient` operations within the same async context. `async-stripe` wraps the underlying `stripe` objects and makes their methods awaitable. Direct `stripe` module usage will be synchronous and block the event loop.
fix
Perform all Stripe operations exclusively through the `async_stripe.StripeClient` instance within your `async with` block.
affects: All versions
Upgrade
Version history
6.1.0latest on PyPI · released Nov 18, 2023
Audit
Dependencies
striperequiredCore dependency; async-stripe wraps the official `stripe-python` library.
Agent activity
59 hits · last 30 days
node
48
Perplexity
1
OpenAI (training)
1
Resources
async-stripe — pip install async-stripe · libregistry