A production-ready FastAPI server template with built-in authentication, rate limiting and security headers. This repository provides a solid foundation for building secure, observable FastAPI applications.
- TemplateServer Base Class: Reusable foundation
- FastAPI Framework: Modern, fast, async-ready web framework
- Docker Support: Multi-stage builds with docker-compose orchestration
- Production Patterns: Token generation, SSL certificate handling, health checks
This project uses a TemplateServer base class that encapsulates cross-cutting concerns:
- Request Logging: All requests/responses logged with client IP tracking
- Security Headers: HSTS/CSP/X-Frame-Options automatically applied
- API Key Verification: SHA-256 hashed tokens with secure validation
- Rate Limiting: Configurable limits using
slowapi(in-memory/Redis/Memcached)
Application-specific servers (like ExampleServer in main.py) extend TemplateServer to implement domain-specific endpoints and business logic. The base class handles all infrastructure concerns, letting you focus on your API functionality.
- Python 3.13+
- uv package manager
Install uv:
# Linux/Mac
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"# Clone the repository
git clone https://github.com/javidahmed64592/python-template-server.git
cd python-template-server
# Install dependencies
uv sync --extra devuv run generate-new-token
# ⚠️ Save the displayed token - you'll need it for API requests!# Start the server
uv run python-template-server
# Server runs at https://localhost:443/api
# Swagger UI: https://localhost:443/api/docs
# Redoc: https://localhost:443/api/redoc
# Health check: curl -k https://localhost:443/api/health
# Login (requires authentication): curl -k -H "X-API-Key: your-token-here" https://localhost:443/api/loginTo create your own server:
- Create a subclass of
TemplateServer(seepython_template_server/main.py:ExampleServeras reference) - Implement required methods:
validate_config(): Validate your config modelsetup_routes(): Define your API endpoints
- Add custom routes using FastAPI decorators on
self.app - Configure via
configuration/config.json
See the Software Maintenance Guide for detailed setup instructions.
- API Documentation: API architecture and endpoints
- Docker Deployment Guide: Container orchestration
- Software Maintenance Guide: Development setup, configuration
- Workflows: CI/CD pipeline details
This project is licensed under the MIT License - see the LICENSE file for details.