Install & Compatibility
Where this runs
tested against v3.5.2.20240106 · 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.000s · 18.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
stripe
✓ import stripe-stubs as stripe
✗ import stripe_stubs as stripe
This quickstart demonstrates how to use the `stripe` library. When `types-stripe` is installed (and `stripe` is an older version without inline types), type checkers will automatically pick up the provided type hints, allowing for static analysis of `stripe` API calls and response objects.
import os
import stripe
from typing import Optional
# Set your Stripe API key (usually from environment variables)
# For demonstration, use a placeholder. In real applications, ensure this is securely managed.
stripe.api_key = os.environ.get("STRIPE_SECRET_KEY", "sk_test_YOUR_SECRET_KEY")
def get_customer_email(customer_id: str) -> Optional[str]:
"""
Retrieves a Stripe customer's email.
Type checkers will use types-stripe (or inline stubs if stripe>=7.1.0) to
validate API calls and response types.
"""
try:
# The 'stripe' library methods are typed by types-stripe (if installed and applicable)
customer = stripe.Customer.retrieve(customer_id)
# Type checker knows 'customer' is a stripe.Customer object and 'email' is Optional[str]
print(f"Customer email: {customer.email}")
return customer.email
except stripe.error.StripeError as e:
print(f"Error retrieving customer: {e}")
return None
if __name__ == "__main__":
# This example assumes you have a test customer ID.
# Replace 'cus_example_id' with a real test customer ID if you want to run it.
# Note: Without a valid key and customer, this will raise a StripeError.
customer_id_example = "cus_example_id" # Replace with actual test customer ID
get_customer_email(customer_id_example)
# Example of creating a Customer (showing parameters are typed)
try:
new_customer = stripe.Customer.create(
description="Test customer for types-stripe example",
email="test@example.com"
# metadata={"order_id": "123"} # Other optional typed parameters
)
print(f"Created new customer with ID: {new_customer.id}")
except stripe.error.StripeError as e:
print(f"Error creating customer: {e}")
Upgrade
Version history
3.5.2.20240106latest on PyPI · released Jan 6, 2024
Audit
Dependencies
striperequiredProvides runtime functionality; `types-stripe` only supplies type hints for this library.