async-stripe

6.1.0 · active · verified Sun Apr 12

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`.

Warnings

Install

Imports

Quickstart

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())

view raw JSON →