Example of a simple FastAPI application, with a Postgres DB in a Docker Container. Based on: https://fastapi.tiangolo.com/tutorial/sql-databases/#sql-relational-databases
Before running the application it is recommended to set up a virtual environment.
- In PyCharm, press
CTRL + ALT + S. - Navigate to
Project > Python Interpreter. - Click on
Add interpreterand configure Python 3.11 or higher.
To start a local database, run the following commands:
- Run
docker run -p 5432:5432 --name postgres -e POSTGRES_USER=user -e POSTGRES_PASSWORD=mysecretpassword -d postgresto start a container.
Then, to run the application:
- First install dependencies by running
pip install -r requirements.txt. - Then, from the root folder, start the application by running
python .\main.py. - Go to
localhost:8000.
The uvicorn server will start automatically.
Nox is a command-line tool that automates testing in Python environments. In this project it is used to evaluate code quality and complexity, check typing, run tests, and format code.
To run all Nox sessions, simply run nox in the project directory.
To perform formatting using isort and autoflake, run nox --sessions format.
This will only run the formatting session.
To run all unit tests and check code coverage, run nox --sessions test.
To evaluate code complexity, run nox --sessions complexity.