Production-ready Python backend template with Flowless integration, built with FastAPI and modern async patterns.
- Bridge Validation - Distributed session validation with Flowless
- Validation Modes - Layered security (DISABLED, STANDARD, ADVANCED, STRICT)
- HybridCache - 3-tier caching system (LRU + Redis + Database)
- Trust Tokens - Secure PASETO v4 token management
- Auth Middleware - FastAPI dependencies for route protection
- Multi-Database - Support for PostgreSQL, MySQL, and SQLite
- Environment Config - Type-safe configuration with Pydantic
- Python 3.11+ - Modern Python with type hints
- FastAPI 0.115+ - High-performance async web framework
- SQLAlchemy 2.x - Async ORM with multi-database support
- Pydantic 2.x - Data validation and settings management
- Redis - Distributed caching layer
- PASETO v4 - Secure token generation
- Structlog - Structured logging
- Pytest - Comprehensive testing framework
# Clone the repository
git clone <repository-url>
cd flowfull-python-starter
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt# Copy environment template
cp .env.example .env
# Edit .env with your configuration
nano .envMinimum required configuration:
DATABASE_URL=postgresql://user:pass@localhost:5432/flowfull_db
FLOWLESS_API_URL=https://your-instance.pubflow.com
BRIDGE_VALIDATION_SECRET=your-shared-secret-min-32-chars# Run migrations
alembic upgrade head# Start server with hot reload
uvicorn app.main:app --reload --host 0.0.0.0 --port 3001
# Server will be available at:
# - API: http://localhost:3001
# - Docs: http://localhost:3001/docs
# - Health: http://localhost:3001/health# Start all services (app + PostgreSQL + Redis)
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down# Build image
docker build -t flowfull-python .
# Run container
docker run -p 3001:3001 --env-file .env flowfull-pythonFriendly documentation is available in the /docs directory:
- 00-ARCHITECTURE-OVERVIEW.md - System architecture and diagrams
- 02-CORE-CONCEPTS.md - Implementation of 7 core concepts
- 03-ENVIRONMENT.md - Environment configuration guide
- 04-USAGE-GUIDE.md - Complete usage examples
- QUICK-REFERENCE.md - Quick reference guide
# Format code
black app/ tests/
isort app/ tests/
# Lint code
ruff check app/ tests/
# Type checking
mypy app/
# Run all checks
black app/ tests/ && isort app/ tests/ && ruff check app/ tests/ && mypy app/# Run all tests
pytest
# Run with coverage
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/test_health.py
# Run with verbose output
pytest -v@router.get("/public")
async def public_route() -> dict:
return {"message": "This is public"}from app.lib.auth.middleware import require_auth
from app.lib.auth.bridge_validator import SessionData
@router.get("/profile")
async def get_profile(session: SessionData = Depends(require_auth)) -> dict:
return {
"user_id": session.user_id,
"email": session.email,
"name": session.name
}from app.lib.auth.middleware import optional_auth
@router.get("/content")
async def get_content(session: Optional[SessionData] = Depends(optional_auth)) -> dict:
if session:
return {"message": f"Hello {session.name}!"}
return {"message": "Hello guest!"}from app.lib.auth.middleware import require_user_type
@router.get("/admin")
async def admin_route(session: SessionData = Depends(require_user_type("admin"))) -> dict:
return {"message": "Admin access granted"}from app.lib.cache.cache_instances import profile_cache
@router.get("/users/{user_id}")
async def get_user(user_id: str):
# Check cache first
user = await profile_cache.get(user_id)
if user:
return {"user": user, "cached": True}
# Fetch from database
user = await fetch_user_from_db(user_id)
# Cache for future requests
await profile_cache.set(user_id, user, ttl=600)
return {"user": user, "cached": False}Configure session validation strictness in .env:
# DISABLED - No validation (development only)
# STANDARD - IP validation
# ADVANCED - IP + User-Agent validation
# STRICT - IP + User-Agent + Device ID validation
AUTH_VALIDATION_MODE=STANDARDGenerate a secure PASETO key:
python scripts/generate_paseto_key.pyAdd the generated key to your .env file:
PASETO_PRIVATE_KEY=k4.local.your-generated-key-hereflowfull-python-starter/
βββ app/
β βββ config/
β β βββ environment.py # Pydantic settings
β βββ lib/
β β βββ auth/
β β β βββ bridge_validator.py # Session validation
β β β βββ middleware.py # Auth dependencies
β β β βββ validation_mode.py # Validation modes
β β βββ cache/
β β β βββ hybrid_cache.py # 3-tier cache
β β β βββ cache_instances.py # Cache instances
β β βββ database/
β β β βββ connection.py # Database setup
β β β βββ session.py # Session helpers
β β βββ tokens/
β β β βββ trust_tokens.py # PASETO tokens
β β βββ utils/
β β βββ logger.py # Structured logging
β βββ models/
β β βββ user.py # Example model
β βββ routes/
β β βββ health.py # Health checks
β β βββ api.py # API routes
β βββ main.py # FastAPI app
βββ tests/
β βββ conftest.py # Pytest fixtures
β βββ test_health.py # Health tests
β βββ test_api.py # API tests
βββ scripts/
β βββ generate_paseto_key.py # Key generation
βββ alembic/ # Database migrations
βββ .env.example # Environment template
βββ pyproject.toml # Project config
βββ requirements.txt # Dependencies
βββ Dockerfile # Docker config
βββ docker-compose.yml # Docker Compose
Required for production:
ENVIRONMENT=production
DATABASE_URL=postgresql://user:pass@host:5432/db
FLOWLESS_API_URL=https://your-instance.pubflow.com
BRIDGE_VALIDATION_SECRET=your-production-secret-min-32-chars
PASETO_PRIVATE_KEY=k4.local.your-production-key
REDIS_URL=redis://redis-host:6379
CORS_ORIGINS=https://yourdomain.com# Using Uvicorn with workers
uvicorn app.main:app --host 0.0.0.0 --port 3001 --workers 4
# Using Gunicorn with Uvicorn workers
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:3001| Metric | Target | Notes |
|---|---|---|
| Cache Hit Rate | >90% | LRU + Redis |
| Auth Latency (cached) | <5ms | LRU hit |
| Auth Latency (Redis) | <15ms | Redis hit |
| Auth Latency (Bridge) | <100ms | Flowless validation |
| Request Throughput | >10k req/s | With cache |
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT License - see LICENSE file for details
- Flowless Documentation: Flowless Docs
- FastAPI Documentation: FastAPI
- Pydantic Documentation: Pydantic
- SQLAlchemy Documentation: SQLAlchemy
For issues and questions:
- Open an issue on GitHub
- Check the documentation in
/to-dodirectory - Contact: support@pubflow.com
Built with β€οΈ by the Pubflow Team