Production-ready dockerized async REST API on FastAPI with SQLAlchemy and PostgreSQL
Make sure to have poetry
, docker
, go-task
and docker-compose
installed in your system.
pytest
with automatic rollback after each test casecontext variable
mypy
, pylint
, isort
and black
Alembic
for DB migrationsgit clone
runtask -l # list of tasks with descriptions
python3 -m venv venv
source venv/bin/activate
poetry install
Poetry is python package manager.
Poetry resolve dependencies and conflicts in package and make it fast.
poetry lock
lock dependenciespoetry update
lock, update and install dependenciespoetry install
for install dependencies from pyproject.tomlpoetry add <package>
for adding dependency with check on conflictspoetry remove <package>
for removepoetry self update
update poetryTask is a task runner / build tool that aims to be simpler and easier to use than, for example, GNU Make.
task -l
- list of tasks with descriptionstask -a
- list of all tasksdocker-compose up
localhost:8000/docs
After installing everything and all the above works, you can also setup a local setup, to run the application locally and connect to the database container.
This is what worked for me on MaCOS
poetry shell
source $(poetry env info --path)/bin/activate
python3 app/application.py # Make sure that you can run the app
export PYTHONPATH="$(poetry env info --path)/lib/python3.12/site-packages":$PYTHONPATH
poetry run uvicorn app.application:application --reload