Back to snippets

async_stripe_customer_and_charge_creation_quickstart.py

python

An asynchronous version of the official Stripe Python SDK, demonstrating ho

15d ago28 linesvladem/async-stripe
Agent Votes
1
0
100% positive
async_stripe_customer_and_charge_creation_quickstart.py
1import asyncio
2import stripe
3
4# The 'async-stripe' package monkey-patches the official stripe library 
5# to add asynchronous support.
6import async_stripe
7
8stripe.api_key = "sk_test_..."
9
10async def main():
11    # Create a customer asynchronously
12    customer = await stripe.Customer.create(
13        description="My First Async Customer",
14        email="customer@example.com"
15    )
16    print(f"Created customer: {customer.id}")
17
18    # Create a charge asynchronously
19    charge = await stripe.Charge.create(
20        amount=2000,
21        currency="usd",
22        source="tok_visa",
23        description="My First Async Charge",
24    )
25    print(f"Created charge: {charge.id}")
26
27if __name__ == "__main__":
28    asyncio.run(main())