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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.724s · 26.8MB
glibcpy 3.10–3.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.fixConsult 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.fixEnsure 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.fixAlways 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.fixPerform 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.