Larz › Monetize an API in Python
Monetize your Python API
Keys, metering, validation, and docs — the complete stack for a paid JSON API, in one framework.
pip install larz
@app.api_key_required(plan="pro")
@app.validate({"text": {"type": str, "required": True}})
@app.metered("$0.01/call")
@app.post("/api/summarize")
def summarize(req):
return {"summary": run(req.data["text"])}
The pieces
- API keys —
app.auth.issue_api_key(plan="pro"); billing follows the key - Metering — per-call charges against prepaid credit, clean
402when empty - Validation — reject bad input with field-level errors
- OpenAPI docs —
app.enable_docs()→/openapi.json+/docs - Webhooks — notify customers, signed and retried
See the step-by-step tutorial and the runnable
examples/paid_api.py.FAQ
How do I charge for a Python API?
Issue API keys with app.auth.issue_api_key(plan=...), gate the endpoint with @app.api_key_required, and meter it with @app.metered. Larz bills each key per call.
Does Larz generate API docs?
Yes — app.enable_docs() serves an OpenAPI spec at /openapi.json and a browsable page at /docs, generated from your routes and validation schemas.