This is the completed version of the project on my blog post here. The project demonstrates how to create a FastAPI project with async SQLAlchemy, Alembic, PostgreSQL and Docker.
-
Create a virtual environment and activate it:
$ virtualenv venv --python python3.11 $ source venv/bin/activate
-
Install the dependencies:
$ pip install -r requirements.txt
-
Start the PostgreSQL database:
$ docker compose up -d postgres
-
Run the migrations:
$ alembic upgrade head
-
Start the FastAPI server:
$ python3 -m src.main
You can access the swagger docs at http://localhost:8000/docs.
Simply just run $ docker compose up -d
to start the project with Docker. You can follow the logs
using $ docker compose logs -f backend
command. You can stop the project with $ docker compose down
.
You can access the swagger docs at http://localhost:8000/docs.