A minimal FastAPI boilerplate for integrating Dodo Payments into your Python application.
- Quick Setup - Get started in under 5 minutes
- Payment Integration - Pre-configured checkout flow using
dodopaymentsPython SDK - Modern UI - Clean, dark-themed pricing page with Tailwind CSS
- Webhook Handler - Ready-to-use webhook endpoint for payment events
- Customer Portal - One-click subscription management
- Type Safety - Fully typed with Pydantic models
- Pre-filled Checkout - Demonstrates passing customer data to improve UX
Before you begin, make sure you have:
- Python 3.8+ (required for FastAPI and the Dodo Payments SDK)
- Dodo Payments account (to access API and Webhook Keys from dashboard)
git clone https://github.com/dodopayments/fastapi-boilerplate.git
cd fastapi-boilerplatepython3 -m venv venv
source venv/bin/activatepip install -r requirements.txtSign up at Dodo Payments and get your credentials from the dashboard:
- API Key: Dashboard → Developer → API Keys
- Webhook Key: Dashboard → Developer → Webhooks
Make sure you're in Test Mode while developing!
Create a .env file in the root directory:
cp .env.example .envUpdate the values with your Dodo Payments credentials:
DODO_PAYMENTS_API_KEY=your_api_key_here
DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_signing_key_here
DODO_PAYMENTS_RETURN_URL=http://localhost:8000
DODO_PAYMENTS_ENVIRONMENT=test_modeUpdate app/lib/products.py with your actual product IDs from Dodo Payments:
products: List[Product] = [
Product(
product_id="pdt_001", # Replace with your product ID
name="Basic Plan",
description="Get access to basic features and support",
price=9999, # in cents
features=[
"Access to basic features",
"Email support",
"1 Team member",
"Basic analytics",
],
),
# ... add more products
]uvicorn app.main:app --reload --port 8000Open http://localhost:8000 to see your pricing page!
app/
├── api/
│ ├── checkout.py # Checkout session handler
│ ├── portal.py # Customer portal redirect
│ └── webhook.py # Webhook event handler
├── core/
│ └── config.py # Configuration settings
├── lib/
│ ├── customers.py # Customer utilities (normalization, payload helpers)
│ └── products.py # Product definitions
├── templates/
│ ├── base.html # Base template
│ └── index.html # Pricing page
├── static/
│ └── css/ # Custom styles (if needed)
└── main.py # App entry point
Edit app/lib/products.py to modify:
- Product IDs (from your Dodo dashboard)
- Pricing
- Features
- Descriptions
In app/templates/index.html, replace the hardcoded values with your actual user data:
const customerData = {
name: "John Doe", // Replace with actual logged-in user's name
email: "john@example.com" // Replace with actual logged-in user's email
};In a production app, you would get this data from your authentication system (e.g., session, JWT token, etc.).
In app/templates/index.html, replace the hardcoded customer ID:
const customerId = "cus_001"; // Replace with actual customer IDThe boilerplate demonstrates handling two webhook events in app/api/webhook.py:
subscription.active- Triggered when a subscription becomes activepayment.succeeded- Triggered when a payment is successful
Add your business logic inside these handlers:
if event_type == "subscription.active":
# Grant access to your product
# Update user database
# Send welcome email
passAdd more webhook events as needed.
For local development, you can use tools like ngrok to create a secure tunnel to your local server and use it as your webhook URL. Remember to update your .env file with the correct webhook verification key.
For production, you can use Gunicorn with Uvicorn workers:
pip install gunicorn
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorkerYou can deploy this FastAPI application to any platform that supports Python/FastAPI: Note: FastAPI on Vercel is possible via Python Serverless Functions but is outside the scope of this boilerplate. Prefer Railway/Render for FastAPI.
Don't forget to add your environment variables (API key, Webhook key, Return URL, Environment) in the deployment platform's dashboard.
After deploying, update your webhook URL in the Dodo Payments Dashboard:
https://yourdomain.com/api/webhook
Need help? Reach out: