Examples & Recipes¶
Learn by doing
Every example below is a complete, runnable application. Clone the repo, pick a recipe, and have it running in seconds. Examples are organized by difficulty so you can progress at your own pace.
Run an Example¶
Get any example running in under a minute.
# Clone the repository
git clone https://github.com/jagadeesh32/cello.git
cd cello
# Set up the environment
python -m venv .venv && source .venv/bin/activate
pip install -e .
# Run any example
python examples/hello.py
Live reload for development
Add --reload to automatically restart when you edit the file:
Beginner¶
Start here if you are new to Cello. These examples cover the fundamentals with minimal code.
-
Hello World
Beginner { .md-tag }
The simplest possible Cello app — one route, one response. Understand the core pattern that every Cello application follows.
Features used:
App@app.get()dict response -
REST API
Beginner { .md-tag }
Build a complete CRUD API with JSON validation, proper status codes, and error handling. The bread and butter of web development.
Features used:
BlueprintResponse.json()request.json()status codes -
Form Handling
Beginner { .md-tag }
Accept form submissions and file uploads with multipart support. Covers both URL-encoded forms and file uploads.
Features used:
request.form()multipartfile uploads -
JWT Authentication
Beginner { .md-tag }
Secure your routes with JSON Web Tokens. Covers token generation, verification, and protecting endpoints with a lightweight auth guard.
Features used:
JWTGuardsrequest.headers401 responses -
Database Integration
Beginner { .md-tag }
Connect to SQLite or PostgreSQL using Cello's async DB helpers. Create tables, run queries, and map results to Python dicts with zero boilerplate.
Features used:
async_dbconnection poolquery helpersmigrations -
Query Parameters & Validation
Beginner { .md-tag }
Parse and validate URL query parameters with automatic type coercion, default values, and descriptive error messages on invalid input.
Features used:
request.queryvalidators400 error responses
Intermediate¶
Ready to build real applications? These examples combine multiple Cello features into production-worthy patterns.
-
Full-Stack App
Intermediate { .md-tag }
A complete web application with HTML templates, static file serving, form handling, and database integration. Everything you need for a traditional web app.
Features used:
TemplatesStatic filesSessionsBlueprintsCSRF -
Microservices
Intermediate { .md-tag }
Break your application into independent services that communicate via HTTP and message queues. Includes service discovery and health checks.
Features used:
gRPCMessage queuesHealth checksCircuit breakerOpenTelemetry -
Real-time Dashboard
Intermediate { .md-tag }
Live-updating dashboard using WebSocket and Server-Sent Events. Push data to connected clients in real time with automatic reconnection.
Features used:
WebSocketSSEBackground tasksPrometheus metrics -
Redis Caching
Intermediate { .md-tag }
Cache expensive query results in Redis with the cache-aside pattern. Covers TTL management, cache invalidation on writes, and cache warming strategies.
Features used:
Redis middlewareCachingTTLcache invalidation -
Background Tasks
Intermediate { .md-tag }
Offload slow work — emails, image processing, reports — to background workers. Covers task queues, retries, progress tracking, and scheduled cron jobs.
Features used:
task_queue@background_taskretrycron -
GraphQL API
Intermediate { .md-tag }
Expose a fully-typed GraphQL schema alongside your REST routes. Demonstrates queries, mutations, subscriptions, and DataLoader for N+1 query prevention.
Features used:
GraphQLschemaresolversDataLoadersubscriptions -
File Storage (S3-Compatible)
Intermediate { .md-tag }
Upload, download, and stream files to S3-compatible object storage. Handles multipart uploads, pre-signed URLs, and chunked streaming responses.
Features used:
multipartstreaming responseS3 clientpre-signed URLs
Enterprise¶
Battle-tested patterns for large-scale production systems. These examples demonstrate how Cello handles the complexity of enterprise software.
-
Multi-tenant SaaS
Advanced { .md-tag }
Tenant isolation at the middleware level with per-tenant databases, RBAC, and custom domain routing. The foundation for any SaaS product.
Features used:
Guards (RBAC)MiddlewareJWTDependency injectionData partitioning -
API Gateway
Advanced { .md-tag }
A centralized API gateway with authentication, rate limiting, request transformation, and upstream load balancing. Control all traffic in one place.
Features used:
Rate limitingJWT authCORSCircuit breakerPrometheusRequest ID tracing -
Event Sourcing
Advanced { .md-tag }
Event-driven architecture with CQRS, an append-only event store, and the Saga pattern for distributed transaction coordination.
Features used:
Event storeCQRSSaga patternBackground tasksMessage queues -
Rate Limiting & DDoS Protection
Advanced { .md-tag }
Protect your APIs with sliding-window rate limiting, IP allowlists/blocklists, adaptive throttling, and Prometheus alerting when thresholds are breached.
Features used:
Rate limitingRedisIP filteringPrometheusCircuit breaker -
Health Checks & Observability
Advanced { .md-tag }
Production-ready
/health,/ready, and/metricsendpoints. Integrates with Kubernetes liveness/readiness probes, OpenTelemetry tracing, and Grafana dashboards.Features used:
Health checksPrometheusOpenTelemetryStructured logging -
OAuth2 & Social Login
Advanced { .md-tag }
Complete OAuth2 authorization code flow with Google, GitHub, and custom providers. Covers PKCE, token refresh, session management, and account linking.
Features used:
OAuth2JWTSessionsPKCEToken refresh
Example Architecture¶
How Cello's features layer together in a typical application.
graph LR
A[Client Request] --> B[Middleware Pipeline]
B --> C{Router}
C -->|Blueprint A| D[Auth Guards]
C -->|Blueprint B| E[Public Handler]
D --> F[Handler + DI]
F --> G[Response]
E --> G
G --> H[Middleware Pipeline]
H --> I[Client Response]
style A fill:#FFF3E0,stroke:#E65100,color:#BF360C
style I fill:#FFF3E0,stroke:#E65100,color:#BF360C
style C fill:#FFF3E0,stroke:#E65100,color:#BF360C
style D fill:#F3E5F5,stroke:#7B1FA2,color:#4A148C Feature Matrix¶
Which features are used in each example? Select a difficulty level:
| Feature | Hello World | REST API | Forms | JWT Auth | Database | Query Params |
|---|---|---|---|---|---|---|
| Routing | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Blueprints | ✅ | |||||
| Middleware | ✅ | ✅ | ||||
| JWT Auth | ✅ | |||||
| Guards / RBAC | ✅ | |||||
| File Uploads | ✅ | |||||
| Database | ✅ | |||||
| Query Params | ✅ |
| Feature | Full-Stack | Microservices | Dashboard | Redis Cache | Background | GraphQL | File Storage |
|---|---|---|---|---|---|---|---|
| Routing | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Blueprints | ✅ | ✅ | ✅ | ||||
| Middleware | ✅ | ✅ | ✅ | ✅ | |||
| JWT Auth | ✅ | ✅ | |||||
| Guards / RBAC | ✅ | ||||||
| WebSocket / SSE | ✅ | ||||||
| Dependency Injection | ✅ | ✅ | |||||
| Background Tasks | ✅ | ✅ | ✅ | ||||
| Prometheus Metrics | ✅ | ✅ | |||||
| Redis / Caching | ✅ | ||||||
| File Uploads | ✅ | ✅ | |||||
| Database | ✅ | ✅ | ✅ | ||||
| OAuth2 / Sessions | ✅ |
| Feature | Multi-tenant | API Gateway | Event Sourcing | Rate Limiting | Health Checks | OAuth2 |
|---|---|---|---|---|---|---|
| Routing | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Blueprints | ✅ | ✅ | ✅ | ✅ | ||
| Middleware | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| JWT Auth | ✅ | ✅ | ✅ | |||
| Guards / RBAC | ✅ | ✅ | ||||
| Dependency Injection | ✅ | ✅ | ||||
| Background Tasks | ✅ | |||||
| Prometheus Metrics | ✅ | ✅ | ✅ | |||
| Redis / Caching | ✅ | ✅ | ||||
| Circuit Breaker | ✅ | ✅ | ||||
| Database | ✅ | ✅ | ✅ | |||
| OpenTelemetry | ✅ | |||||
| Message Queues | ✅ | |||||
| OAuth2 / Sessions | ✅ | ✅ |
More Examples¶
Browse the full collection of examples in the GitHub repository. Contributions are welcome — see the Contributing Guide to add your own example.