Welcome to the comprehensive examples collection for Catzilla v0.2.0 - a high-performance Python web framework with C-accelerated routing using libuv for async operations.
Catzilla is designed for maximum performance with:
- C-accelerated routing for ultra-fast request handling
- Zero-allocation middleware system for minimal overhead
- Built-in async operations handled by libuv in C (no
async defneeded!) - Multi-layer caching with memory, Redis, and disk support
- Advanced validation and data modeling
This directory contains 18 comprehensive examples organized into 9 categories, each demonstrating different aspects of the Catzilla framework:
Essential framework features and basic patterns.
| File | Description | Key Features |
|---|---|---|
debug_logging.py |
Comprehensive debugging and logging system | Custom loggers, request tracing, performance monitoring, structured logging |
router_groups.py |
Advanced routing patterns and URL groups | Route groups, nested routing, parameter validation, middleware per group |
Data validation and model definitions.
| File | Description | Key Features |
|---|---|---|
models_and_fields.py |
Data models and field validation | Pydantic-style models, custom validators, type checking, serialization |
query_header_form.py |
Request validation patterns | Query parameter validation, header validation, form data processing |
Asynchronous task processing and scheduling.
| File | Description | Key Features |
|---|---|---|
scheduling.py |
Task scheduling and cron-like operations | Scheduled tasks, periodic jobs, task queues, retry logic |
monitoring.py |
Task monitoring and health tracking | Task status tracking, performance metrics, failure handling |
Service management and dependency patterns.
| File | Description | Key Features |
|---|---|---|
scoped_services.py |
Service scoping and lifecycle management | Singleton services, request-scoped services, service lifetimes |
factories.py |
Dynamic service factories and providers | Factory patterns, service providers, dynamic configuration |
Smart caching system with multi-level storage.
| File | Description | Key Features |
|---|---|---|
basic_cache_example.py |
Basic Smart Cache usage and function caching | @cached decorator, direct cache operations, TTL management, statistics |
smart_cache_example.py |
Advanced multi-level caching with middleware | Memory/Redis/Disk caching, cache middleware, conditional rules, monitoring |
cache_configurations.py |
Different cache configuration patterns | Memory-only, persistent, distributed configs, performance comparison |
Request/response processing middleware.
| File | Description | Key Features |
|---|---|---|
ordering.py |
Middleware execution order and priorities | Middleware priorities, execution chains, order control |
custom_hooks.py |
Custom middleware with lifecycle hooks | Custom middleware creation, request/response hooks, error handling |
HTTP streaming and real-time data.
| File | Description | Key Features |
|---|---|---|
response_streams.py |
HTTP response streaming | Chunked responses, server-sent events, data streaming |
connection_management.py |
Connection pooling and management | Connection pools, keep-alive, connection optimization |
File handling and static content serving.
| File | Description | Key Features |
|---|---|---|
upload_handling.py |
File upload processing and validation | Multipart uploads, file validation, image processing, storage |
static_serving.py |
Static file serving with optimization | Static file serving, caching, compression, CDN integration |
Multi-layer caching strategies.
| File | Description | Key Features |
|---|---|---|
multi_layer.py |
Multi-layer caching (memory, Redis, disk) | Cache layers, fallback strategies, cache warming, metrics |
performance_optimization.py |
Cache optimization strategies | Performance optimization, cache analytics, predictive caching |
Common patterns and real-world solutions.
| File | Description | Key Features |
|---|---|---|
rest_api_patterns.py |
Complete REST API with CRUD operations | REST patterns, CRUD operations, pagination, filtering, error handling |
auth_patterns.py |
Authentication & authorization patterns | JWT auth, API keys, RBAC, rate limiting, session management |
# Install Catzilla framework
pip install catzilla
# Optional dependencies for advanced examples
pip install redis psutil pillow jwtEach example is a standalone application. To run any example:
# Navigate to the examples directory
cd examples/
# Run a specific example
python core/debug_logging.py
python validation/models_and_fields.py
python recipes/rest_api_patterns.pyMost examples run on http://localhost:8000 and include:
- 📖 API documentation at the root endpoint (
/) - 🔍 Interactive examples with curl commands
- 🏥 Health check endpoint (
/health) - 📊 Metrics and monitoring endpoints
Perfect for beginners to understand Catzilla's basic concepts and routing system.
Try first:
python core/debug_logging.py
# Visit http://localhost:8000 for documentationLearn how to validate and process incoming data safely.
Key concepts:
- Model-based validation
- Custom field validators
- Request data processing
Handle long-running tasks without blocking requests.
Use cases:
- Email sending
- Image processing
- Data synchronization
- Scheduled maintenance
Manage services and dependencies cleanly.
Benefits:
- Testable code
- Service isolation
- Configuration management
- Lifecycle control
Intercept and modify requests/responses.
Common middleware:
- Authentication
- Logging
- Rate limiting
- CORS handling
Handle large responses and real-time data efficiently.
Applications:
- File downloads
- Live data feeds
- Server-sent events
- Progress tracking
Handle file uploads, downloads, and static content.
Features:
- Secure file uploads
- Image processing
- Static file optimization
- CDN integration
Implement multi-layer caching for better performance.
Cache layers:
- Memory (fastest)
- Redis (distributed)
- Disk (persistent)
Production-ready patterns for common use cases.
Essential patterns:
- REST API design
- Authentication flows
- Error handling
- API documentation
Complex features for large-scale applications.
Enterprise needs:
- Real-time streaming
- Connection management
- Background task coordination
- Performance monitoring
core/debug_logging.py
↓
core/router_groups.py
↓
validation/models_and_fields.py
↓
recipes/rest_api_patterns.py
middleware/custom_hooks.py
↓
cache/multi_layer.py
↓
files/upload_handling.py
↓
recipes/auth_patterns.py
streaming/response_streams.py
↓
background_tasks/scheduling.py
↓
streaming/connection_management.py
- JWT Authentication:
recipes/auth_patterns.py - API Key Management:
recipes/auth_patterns.py - Role-based Access Control:
recipes/auth_patterns.py - Rate Limiting:
recipes/auth_patterns.py
- Caching Strategies:
cache/multi_layer.py,cache/performance_optimization.py - Connection Pooling:
streaming/connection_management.py
- Server-sent Events:
streaming/response_streams.py - Live Data Streaming:
streaming/response_streams.py
- File Uploads:
files/upload_handling.py - Image Processing:
files/upload_handling.py - Data Validation:
validation/models_and_fields.py,validation/query_header_form.py - Background Tasks:
background_tasks/scheduling.py,background_tasks/monitoring.py
- Health Monitoring:
background_tasks/monitoring.py - Distributed Tracing:
core/debug_logging.py
Catzilla uses C-accelerated async operations with libuv, which means:
# ✅ CORRECT - Use regular def (not async def)
@app.get("/users")
def get_users(request: Request) -> Response:
data = request.json() # ✅ Synchronous call
return JSONResponse(data)
# ❌ WRONG - Don't use async def
async def get_users(request: Request) -> Response:
data = await request.json() # ❌ Don't await
return JSONResponse(data)Why? Catzilla handles all async operations internally in C using libuv, making your Python code simpler and faster!
Each example includes comprehensive testing patterns:
# Run example with test data
python recipes/rest_api_patterns.py
# Use curl to test endpoints
curl http://localhost:8000/
curl http://localhost:8000/health
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"test"}' \
http://localhost:8000/api/usersFound an issue or want to improve an example?
- Report Issues: Open an issue describing the problem
- Suggest Improvements: Propose enhancements or new examples
- Submit PRs: Follow the existing code style and patterns
- Framework Docs: Catzilla Documentation
- API Reference: Check the framework's main documentation
- Example Issues: Report example-specific issues in the main repository
After exploring these examples:
- Build Your Application: Use the patterns in your own projects
- Performance Tuning: Apply caching and optimization strategies
- Production Deployment: Use microservices and monitoring patterns
- Community: Share your Catzilla applications with the community!
Happy coding with Catzilla! 🚀
These examples demonstrate the power and simplicity of building high-performance web applications with Catzilla's C-accelerated framework.