Fastapi Uvicorn Sqlalchemy Alembic
This development setup is tested in Linux environment. Overall components are deployed in Docker environment. It might work in Docker in Windows environment; try at your own risk.
- Docker: container runtime environment
- Docker-compose: to package and manage multiple images together
- (Optional) Make: to execute the makefile to help setup the development environment with minimum effort (recommended).
- (Optional) Python version minimum 3.8: if developing in local environment
- cron - to set up scheduled email send task
- Clone github repository and go inside repository folder.
- Create your .env file from .env.example or add names from this file to environment variables.
- Ensure 8000 and 5432 are not in use. If not possible, ports definitions can be changed in docker-compose.yml.
- Build and start project with docker compose. Run with make:
make buildup
or with docker command :docker-compose up --build
for V1 ordocker compose up --build
for V2. - To load initial data into database run command
make db-load
or enter postgres container and runpsql -d $(DATABASE_NAME) -U $(DATABASE_USERNAME) < /docker-entrypoint-initdb.d/dump.sql
. - Development server is running under localhost:8000
SwaggerUI API documentation is available under http://127.0.0.1:8000/docs
Alternative ReDoc documentation is under http://127.0.0.1:8000/redoc
Openapi JSON is under http://127.0.0.1:8000/v1/openapi.json
All GET requests are publicly available. PUT, POST and DELETE queries can be used after login, except for create-user
POST request.
To develop faster with docker containers in main directory there is file Makefile. Inside are shortcuts to run commands faster inside docker container without need to manually execute them locally. For example:
make test
- run pytest inside container and generate code coverage report.make lint-all
- run all linting libraries to check code quality
On main repository root are two files crontab
and cron.sh
.
cron.sh
is executing back-end docker container and running python script to send email.crontab
is an example script showing configuration to run cron job on the server
Ensure that cron is installed on your system. Adjust crontab
path to project and log file. Ensure that cron process is running if not run command cron -f
. Add lines from crontab
file to server configuration by running crontab -e
. Save file and check if configuration is there crontab -l
.