|
6 | 6 |
|
7 | 7 | [](https://github.com/akcelero/python-service-template/actions/) |
8 | 8 |
|
| 9 | +--- |
| 10 | + |
| 11 | +A production-ready template for building scalable Python microservices with FastAPI, featuring modern development tools and best practices. |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- FastAPI Framework: High-performance async web framework with automatic API documentation |
| 16 | +- Authentication: JWT token handling with joserfc |
| 17 | +- Database Integration: SQLAlchemy ORM with PostgreSQL for production and SQLite for testing |
| 18 | +- Testing Suite: Comprehensive test setup with pytest |
| 19 | +- Code Quality: |
| 20 | + - Pre-configured tools for maintaining high code standards |
| 21 | + - Ruff: Lightning-fast Python linter and formatter |
| 22 | + - MyPy: Static type checking |
| 23 | + - Bandit: Security vulnerability scanner |
| 24 | +- Development Workflow: Streamlined development with Just command runner |
| 25 | +- Database Migrations: Alembic for database schema management |
| 26 | +- Containerization: Docker and Docker Compose configuration included |
| 27 | + |
| 28 | +## Tech Stack |
| 29 | + |
| 30 | +### Core Dependencies |
| 31 | +- FastAPI - Modern web framework for building APIs |
| 32 | +- Uvicorn - Lightning-fast ASGI server |
| 33 | +- SQLAlchemy - Python SQL toolkit and ORM |
| 34 | +- Alembic - Database migration tool |
| 35 | +- joserfc - JWT token handling |
| 36 | + |
| 37 | +### Development Tools |
| 38 | +- Ruff - Python linting and formatting |
| 39 | +- MyPy - Static type checking |
| 40 | +- Bandit - Security testing |
| 41 | +- pytest - Testing framework |
| 42 | +- Just - Command runner |
| 43 | +- Pre-commit - Git hooks framework |
| 44 | + |
| 45 | +## Quick Start |
| 46 | +### Prerequisites |
| 47 | +- Python 3.13+ |
| 48 | +- Docker and Docker Compose |
| 49 | +- Just command runner |
| 50 | +- uv package manager |
| 51 | + |
| 52 | +## Installation |
| 53 | +1. Clone or use this template: |
| 54 | +```bash |
| 55 | +git clone git@github.com:akcelero/python-service-template.git |
| 56 | +cd python-service-template |
| 57 | +``` |
| 58 | + |
| 59 | +2. Install dependencies: |
| 60 | +```bash |
| 61 | +uv sync |
| 62 | +``` |
| 63 | + |
| 64 | +3. Set up environment variables: |
| 65 | +```bash |
| 66 | +cp .env.example .env |
| 67 | +# Edit .env with your configuration |
| 68 | +``` |
| 69 | + |
| 70 | +4. Start the development environment: |
| 71 | +```bash |
| 72 | +just build # Build and start with Docker |
| 73 | +# or |
| 74 | +just up # Start services |
| 75 | +``` |
| 76 | + |
| 77 | +5. Run database migrations: |
| 78 | +```bash |
| 79 | +just migrate |
| 80 | +``` |
| 81 | + |
| 82 | +### Testing |
| 83 | +The template includes comprehensive testing setup: |
| 84 | +- Unit Tests: Fast, isolated tests for individual components |
| 85 | +- Integration Tests: Database and API endpoint testing |
| 86 | +- Security Tests: Automated vulnerability scanning |
| 87 | +```bash |
| 88 | +# Run all tests |
| 89 | +just test |
| 90 | + |
| 91 | +# Run specific test file |
| 92 | +just pytest tests/test_specific.py |
| 93 | +``` |
| 94 | + |
| 95 | +## Database |
| 96 | + |
| 97 | +Development |
| 98 | +- PostgreSQL: Production-grade database for development |
| 99 | +- Automatic migrations: Schema changes managed with Alembic |
| 100 | + |
| 101 | +Testing |
| 102 | +- SQLite: Fast, in-memory database for tests |
| 103 | +- Isolated transactions: Each test runs in isolation |
| 104 | + |
| 105 | +## Environment Variables |
| 106 | +Ensure these are set in production: |
| 107 | +- DATABASE_URL: PostgreSQL connection string |
| 108 | +- JWT_SECRET_KEY: Secret for JWT token signing |
| 109 | +- ENVIRONMENT: Set to "production" |
| 110 | + |
| 111 | +## API Documentation |
| 112 | +When running the service, interactive API documentation is available at:<br> |
| 113 | +Swagger UI: http://localhost:8000/docs<br> |
| 114 | +ReDoc: http://localhost:8000/redoc |
| 115 | + |
| 116 | +## License |
| 117 | +This template is open source and available under the MIT License.<br> |
| 118 | +Ready to build your next microservice? This template provides everything you need to get started quickly while maintaining production-ready standards. Happy coding! 🚀 |
0 commit comments