Example REST web service for internet library with:
- clean architecture with interfaces, layers and entities
- Dependency Injection with dishka
- auto tests with pytest
- formatting and linting with ruff and mypy
- Dockerfile with best practices
- CI/CD with Github Workflows with separated actions
- pre-commit features
Creating new venv in project folder and install all dependencies with poetry:
make develop
Start postgres container described in docker-compose.dev.yaml
from scratch:
make local
The tests must be run after the dependencies are installed and when the make local
process is running separately:
pytest -vx ./tests
Remember that to connect to the database, you must specify the environment
variable APP_DB_DSN
python -m library.adapters.database upgrade head
Don't forget to apply migrations with the above command first.
python -m library.adapters.database revision --autogenerate -m "Your message"
Separate commands are written in the Makefile
to run dependency
installation, checks, and testing. They have the suffix -ci
make develop-ci # install dependencies
make lint-ci # run linters - ruff and mypy
make test-ci # run tests with pytest and coverage
List of routes:
GET /api/v1/books/ Fetch Books
POST /api/v1/books/ Create Book
GET /api/v1/books/{book_id}/ Fetch Book by ID
PATCH /api/v1/books/{book_id}/ Update Book by ID
DELETE /api/v1/books/{book_id}/ Delete Book by ID
GET /api/v1/users/ Fetch Users
POST /api/v1/users/ Create Book
GET /api/v1/users/{user_id}/ Fetch User by ID
PATCH /api/v1/users/{user_id}/ Update User by ID
DELETE /api/v1/users/{user_id}/ Delete User by ID
GET /api/v1/users/{user_id}/books/ Get user books
POST /api/v1/users/{user_id}/books/{book_id}/issue/ Issue Book to User
POST /api/v1/users/{user_id}/books/{book_id}/return/ Return Book from User