A template for a Python FastAPI service:
- Poetry for dependency management
- FastAPI for building the API
- Devcontainer for development environment
- Docker for containerization
- Black & isort 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)
Using python3.12
install poetry
:
pip install poetry
Then install dependencies
poetry install
Run locally
poetry run uvicorn app.main:app --port 8000 --reload
poetry 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 Control
tab 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.py
andapp/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
.