{"id":4436,"library":"async-stripe","title":"async-stripe","description":"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`.","status":"active","version":"6.1.0","language":"en","source_language":"en","source_url":"https://github.com/bhch/async-stripe","tags":["async","asyncio","stripe","payments","api-wrapper"],"install":[{"cmd":"pip install async-stripe","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency; async-stripe wraps the official `stripe-python` library.","package":"stripe","optional":false}],"imports":[{"note":"Async operations require the `async_stripe.StripeClient` context manager.","wrong":"from stripe import Customer # or similar direct 'stripe' imports","symbol":"StripeClient","correct":"from async_stripe import StripeClient"}],"quickstart":{"code":"import asyncio\nimport os\nfrom async_stripe import StripeClient\n\nasync def main():\n    # It's recommended to load API key from environment variables\n    api_key = os.environ.get('STRIPE_API_KEY', 'sk_test_...') \n    \n    # Use async with for proper resource management\n    async with StripeClient(api_key=api_key) as stripe:\n        try:\n            customer = await stripe.Customer.create(email=\"test_user@example.com\", description=\"Test Customer\")\n            print(f\"Customer created: {customer.id}\")\n            \n            # Example: Retrieve the customer\n            retrieved_customer = await stripe.Customer.retrieve(customer.id)\n            print(f\"Retrieved customer email: {retrieved_customer.email}\")\n\n        except Exception as e:\n            print(f\"An error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Consult the `stripe-python` changelog and `async-stripe` release notes. Update API call syntax and object structures as required by the upstream library.","message":"Major 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.","severity":"breaking","affected_versions":"All major version upgrades (e.g., v5.x to v6.x)"},{"fix":"Ensure every call to `stripe.Resource.method(...)` is prefixed with `await`, e.g., `customer = await stripe.Customer.create(...)`.","message":"All 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.","severity":"gotcha","affected_versions":"All versions"},{"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:`.","message":"Avoid 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Perform all Stripe operations exclusively through the `async_stripe.StripeClient` instance within your `async with` block.","message":"Do 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}