The documentation has been completely reorganized to be short, easy to understand, and focused on backend web server context.
Before: Scattered information about env vars After: Clear, step-by-step guidance with multiple options
LUMEN_API_KEY=lumen_sk_...Simple one-liner that shows exactly what to set.
- ✅ 4 different ways to set the API key (
.env, shell export, production platforms, direct pass) - ✅ Production examples (Heroku, AWS, Docker)
- ✅ How to load with
python-dotenv - ✅ Troubleshooting section
Implemented exactly as described in the Lumen docs.
Flow: Frontend → Your Backend (/api/lumen/*) → Lumen API
Shows proxy setup immediately in "Quick Setup" section for all 3 frameworks:
# Flask
@app.route("/api/lumen/<path:path>", methods=["GET", "POST", "PUT", "DELETE"])
def lumen_proxy(path):
handler = lumen_flask_handler(get_user_id=get_user_id)
return handler(path)examples/flask_example.py- Full working example with proxy + direct usageexamples/fastapi_example.py- Full working example with proxy + direct usageFLASK_GUIDE.md- Comprehensive Flask-specific guide
-
README.md (↓ 50% length)
- Installation: 3 simple commands
- Quick Setup: 3 clear steps
- API Reference: Concise examples
- Common Patterns: Real backend scenarios
-
QUICKSTART.md (New, ~150 lines)
- Get started in 5 minutes
- Backend-focused only
- Copy-paste ready code
-
FLASK_GUIDE.md (New, comprehensive)
- Complete Flask integration guide
- 4 ways to set API key
- Multiple auth patterns (Flask-Login, JWT, Session)
- Production checklist
- Troubleshooting
All examples now show:
# Protect API routes
@app.route("/api/protected")
async def protected_endpoint():
status = await get_subscription_status(user_id=user_id)
if not status.get("hasActiveSubscription"):
return {"error": "Subscription required"}, 402
return {"data": "..."}
# Gate features
@app.route("/api/premium")
async def premium_feature():
if not await is_feature_entitled(feature="premium", user_id=user_id):
return {"error": "Upgrade required"}, 403
return {"premium_data": "..."}
# Track usage
@app.route("/api/action")
async def action():
await send_event(name="api_call", value=1, user_id=user_id)
return {"result": "..."}Before: Generic async function examples After: Backend route handlers with real use cases
Examples now include:
- ✅ Flask decorators (
@app.route) - ✅ Error handling (
if "error" in result) - ✅ HTTP status codes (
402,403) - ✅ User authentication patterns
- ✅ Session/JWT extraction
- ✅ Production considerations
| File | Purpose | Length | Target |
|---|---|---|---|
README.md |
Main documentation | ~400 lines | All users |
QUICKSTART.md |
Fast setup guide | ~150 lines | New users |
FLASK_GUIDE.md |
Flask-specific guide | ~300 lines | Flask users |
examples/flask_example.py |
Working Flask app | ~150 lines | Flask users |
examples/fastapi_example.py |
Working FastAPI app | ~150 lines | FastAPI users |
PROJECT_SUMMARY.md |
Technical overview | ~300 lines | Contributors |
- README cut by ~50%
- One-page quickstart guide
- Focused code examples
- Step-by-step setup (1, 2, 3)
- Visual flow diagrams (
Frontend → Backend → Lumen) - Real code examples, not pseudo-code
- Clear comments explaining each section
- All examples use Flask/FastAPI decorators
- Focus on API routes, not standalone scripts
- Common patterns (protect routes, gate features, track usage)
- Production deployment guidance
- Backend proxy setup in all framework examples
- Matches Lumen's official docs pattern
- Security model clearly explained
- Frontend integration examples
Local Development:
# .env file
LUMEN_API_KEY=lumen_sk_...
# Load with
from dotenv import load_dotenv
load_dotenv()Production:
# Heroku
heroku config:set LUMEN_API_KEY=lumen_sk_...
# AWS
eb setenv LUMEN_API_KEY=lumen_sk_...
# Docker
docker run -e LUMEN_API_KEY=lumen_sk_...Override in Code (when needed):
status = await get_subscription_status(
user_id="user_123",
api_key="custom_key" # Optional override
)┌─────────┐ ┌─────────────┐ ┌──────────┐
│ Browser │ ──────> │ Your Backend│ ──────> │ Lumen │
│ │ public │ /api/lumen │ private │ API │
└─────────┘ └─────────────┘ └──────────┘
│
├─ Injects user_id
├─ Uses LUMEN_API_KEY
└─ Validates auth
Benefits:
- ✅ API key never exposed to browser
- ✅ User ID extracted from your auth system
- ✅ Centralized security validation
- ✅ Works with any frontend framework
import asyncio
from lumen import send_event
async def main():
await send_event(name="test", value=1, user_id="123")
asyncio.run(main())from flask import Flask
from lumen import send_event
@app.route("/api/action")
async def action():
user_id = session.get("user_id")
await send_event(name="api_call", value=1, user_id=user_id)
return {"result": "..."}- Read
QUICKSTART.md- 5 minute setup - Choose framework guide:
- Flask:
FLASK_GUIDE.md - FastAPI: Check FastAPI sections in README
- Django: Check Django sections in README
- Flask:
- Run example:
python examples/flask_example.py - Integrate into your app
- ✅ Working code examples you can copy-paste
- ✅ Multiple auth pattern examples
- ✅ Troubleshooting section
- ✅ Production deployment checklist
- ✅ Error handling patterns
- ✅ Testing commands
Result: Documentation is now concise, practical, and perfectly suited for backend web developers! 🚀