Browse by type
A modern, production-ready FastAPI boilerplate with built-in authentication, user management, and notification features. This project follows best practices for API development and includes essential tools and configurations out of the box.
Clone the repository:
bash
git clone git@github.com:{your_username}/python-fast-api.git
cd python-fast-api
Create and activate a virtual environment using uv:
bash
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Install dependencies with uv:
bash
uv pip install -e .
Set up environment variables:
bash
cp .env.example .env
# Edit .env with your configuration
Initialize the database:
bash
alembic upgrade head
Start the development server:
# Development mode with auto-reload
python server.py
# Production mode with Gunicorn and uvloop
gunicorn -c gunicorn.conf.py server:app
The API will be available at http://localhost:8000
API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
The application uses RabbitMQ for background task processing. To process email notifications in the background:
# Start the email worker
python src/cmd/email_worker.py
This worker connects to RabbitMQ and processes email tasks from the queue, allowing the main application to continue processing requests without waiting for emails to be sent.
src/
├── app/ # Application components
│ ├── auth/ # Authentication module
│ ├── user/ # User management
│ ├── user_notification/ # Notification system
│ └── ws/ # WebSockets implementation
├── cmd/ # Command-line tools
│ └── worker/ # Background workers
│ └── email/ # Email processing workers
├── core/ # Core functionality
│ ├── di/ # Dependency injection
│ ├── exception/ # Custom exceptions
│ ├── http/ # HTTP-related code
│ ├── log/ # Logging configuration
│ ├── rabbit_mq/ # RabbitMQ integration
│ ├── service/ # Core services
│ ├── settings/ # Application settings
│ └── web_socket/ # WebSockets core functionality
└── database/ # Database configuration
POST /auth/signup - Register a new userPOST /auth/login - User loginPOST /auth/refresh - Refresh access tokenGET /auth/confirm-email - Confirm email addressPOST /auth/re-send-confirm-email - Resend confirmation emailGET /users - List usersPOST /users - Create a userGET /users/{user_id} - Get user by IDGET /user-notifications - List user notificationsPOST /user-notifications - Create a notificationWebSocket /ws/{user_id} - Real-time connection for user-specific notifications and updatesRequired environment variables are defined in .env.example. Copy this to .env and update the values:
# Application
ENVIRONMENT=dev
LOG_REQUEST=True
LOKI_URL="http://127.0.0.1:3100"
LOKI_ENABLED=False
APP_NAME="App"
SERVICE_NAME="api"
X_API_KEY=
# Database
SQLALCHEMY_DATABASE_URI=mysqlaiomysql://user:password@host/db_name
# JWT
JWT_PUBLIC_KEY="" # base64
JWT_PRIVATE_KEY="" # base64
JWT_ALGORITHM="ES512"
JWT_ACCESS_EXPIRATION_HOURS=8
JWT_REFRESH_EXPIRATION_HOURS=24
JWT_CONFIRM_TOKEN_EXP_HOURS=24
# Email
SMTP_SERVER="smtp.gmail.com"
SMTP_PORT=587
APP_PASSWORD="YOUR_PASSWORD"
FROM_EMAIL="YOUR_EMAIL"
APP_URL="http://localhost:8000"
# RabbitMQ
RABBITMQ_URL="amqp://guest:guest@localhost/"
Run tests with pytest:
pytest
This project enforces strict code quality standards using:
Run Ruff linter:
ruff check .
Run Ruff formatter:
ruff format .
Run Mypy type checking:
mypy .
Create a new migration:
alembic revision --autogenerate -m "description of changes"
Apply migrations:
alembic upgrade head
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
$ claude mcp add python-fast-api \
-- python -m otcore.mcp_server <graph>