This project showcases an API implementation with a persistence layer, serving as a reference for building scalable and maintainable APIs using modern Python backend technologies and best practices.
- Web App Layer: FastAPI
- Persistence Layer: SQLAlchemy, PostgreSQL
- Deployment: Docker Compose
- Database Migrations: Alembic
- Testing: Pytest
- Code Formatting & Linting: Black, Isort, Flake8, Mypy
- Task Automation: Poetry + Taskipy
./app
: Main application package./api
: FastAPI routers and request/response models./db
: SQLAlchemy models, database session management, and CRUD operations (SqlAlchemyRepository
)./services
: Business logic
./tests
: Test suite./migrations
: Alembic migrations
python3.12 -m venv .venv
source .venv/bin/activate
pip install poetry
poetry config virtualenvs.create false
poetry install --with dev
Use the provided .env.example
file to create a .env
file with the necessary environment variables.
Run lint checks
poetry run task lint
Run tests (ensure that db is running docker compose up -d db db-migrate
)
poetry run task test
Run tests in docker
docker compose run --rm test
Run everything in docker
docker compose up
Open http://localhost:8000/docs in your browser to see the API documentation.
- Support other encryption modes
- Measuring test coverage
- Cover all administration endpoints with tests
- Pagination for the list routes
- Timestamp fields for the models (created_at, updated_at)