This project demonstrates how to integrate Stripe payments into a Python application using the stripe library and pydantic-settings for configuration management.
- Python 3.14.2
- uv (recommended)
- mise (optional, for task running)
- A Stripe account and API keys
-
Clone the repository:
git clone <repository-url> cd python-stripe-example
-
Install dependencies: Using
uv:uv sync
-
Configure environment variables: Create a
.envfile in the root directory based on the.env.example(if available) or with the following content:STRIPE_SECRET_KEY=your_stripe_secret_key PAYMENT_SUCCESS_URL=http://localhost:8000/success PAYMENT_CANCEL_URL=http://localhost:8000/cancel
You can run the example script using mise or directly with uv.
mise run mainuv run src/main.pyThe script will create a Stripe Checkout Session for a "Philosopher's Stone" and print the session object to the console.
src/main.py: The main entry point that creates a Stripe Checkout Session.src/config.py: Configuration management usingpydantic-settings.pyproject.toml: Project dependencies and metadata.mise.toml: Task runner configuration.