← Back to all products
$29
Billing Integration
Python billing system for SaaS with subscription plans, usage metering, and invoicing.
PythonMarkdown
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 10 files
billing-integration/
├── LICENSE
├── README.md
├── examples/
│ └── basic_example.py
├── free-sample.zip
├── guide/
│ ├── 01_features.md
│ ├── 02_quick-start.md
│ ├── 03_configuration.md
│ └── 04_project-structure.md
├── index.html
└── src/
└── main.py
📖 Documentation Preview README excerpt
Billing Integration
A complete Python billing system for SaaS applications. Handles subscription plans, customer management, usage metering, invoice generation, and webhook processing — all built on Python's standard library.
Features
- Subscription plans — Free, flat-rate, and metered billing with monthly/yearly intervals
- Customer management — Create customers, link to your internal user/tenant IDs
- Usage metering — Record API calls, storage, compute with idempotency protection
- Invoice generation — Automatic line items for base plan + metered usage
- Webhook processing — Verify HMAC-SHA256 signatures, dispatch to typed handlers
- Trial support — Configurable trial periods per subscription
- Graceful cancellation — Cancel immediately or at period end
- JSON persistence — Save/load state for development and testing
Requirements
- Python 3.10+
- No external dependencies (stdlib only)
Quick Start
# Start the billing server with demo data
python src/main.py --init-demo
# Start on a custom port
python src/main.py --port 8001
Then try the API:
# List available plans
curl http://localhost:8001/api/plans
# Create a customer
curl -X POST http://localhost:8001/api/customers \
-H "Content-Type: application/json" \
-d '{"email": "user@docs.example.com", "name": "Acme Corp", "external_id": "tenant_123"}'
# Subscribe to a plan (use plan ID from /api/plans response)
curl -X POST http://localhost:8001/api/subscriptions \
-H "Content-Type: application/json" \
-d '{"customer_id": "cus_xxx", "plan_id": "plan_xxx", "trial_days": 14}'
# Record usage
curl -X POST http://localhost:8001/api/usage \
-H "Content-Type: application/json" \
-d '{"subscription_id": "sub_xxx", "quantity": 100, "idempotency_key": "req_001"}'
# Generate an invoice
curl -X POST http://localhost:8001/api/invoices/generate \
-H "Content-Type: application/json" \
-d '{"subscription_id": "sub_xxx"}'
API Endpoints
| Method | Path | Description |
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
examples/basic_example.py#!/usr/bin/env python3
"""
Billing Integration — Basic Usage Example
===========================================
Demonstrates the full billing lifecycle:
1. Create plans (free, starter, pro)
2. Create a customer
3. Subscribe to a plan with trial
4. Record metered usage
5. Generate an invoice
6. Process payment
7. Handle cancellation
Run: python3 basic_example.py
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
from main import BillingEngine
def main() -> None:
print("=== Billing Integration — Basic Example ===\n")
engine = BillingEngine(data_dir=Path("/tmp/billing-demo"))
# --- 1. Create subscription plans ---
free = engine.create_plan("Free", price_cents=0, features=["100 API calls/mo"])
starter = engine.create_plan("Starter", price_cents=2900, features=["10K API calls/mo"])
pro = engine.create_plan(
"Pro", price_cents=7900,
features=["100K API calls/mo", "Priority support"],
metered=True, usage_unit="api_call", usage_price_cents=1,
)