A template for a Python FastAPI service:
- uv for dependency management
- FastAPI for building the API
- Devcontainer for development environment
- Docker for containerization
- ruff for code formatting
- pre-commit for code quality checks
- Github Actions for CI/CD
- pytest for testing
- Kamal for deployment (TODO: add Kamal deploy action)
Install uv and python3.12
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.12
Then install dependencies
uv sync --frozen
Run locally
uv run uvicorn app.main:app --port 8000 --reload
uv run pytest
docker build -t app .
docker run -p 8000:8000 -it app
-
If you face an issue with git ssh access while pushing new changes, run
ssh-add $HOME/.ssh/<your ssh key>in terminal outside the devcontainer. -
If you face an issue during devcontainer build, make sure the repo is marked as trusted in VSCode. Check
Source Controltab in the sidebar to mark the repo safe, then rebuild the devcontainer.
The /v1 directory contains a sample API router demonstrating basic CRUD operations for users:
- Endpoints: Create, Read, Update, Delete users
- Router setup:
app/v1/routers/base.pyandapp/v1/routers/users.py - User model:
app/v1/models/user.py - User management:
app/v1/services/user/user_manager.py
Use the samples as a starting point for your own API endpoints. View available endpoints at http://localhost:8000/docs.