This is a template for a FastAPI application integrated with PostgreSQL, packaged as a Docker container. FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.
- FastAPI for building API endpoints
- PostgreSQL for database storage
- Docker for containerization
- SQLAlchemy as the ORM (Object-Relational Mapping)
- Complete authorization operations
- Test setup
- Docker installed
- Docker Compose installed
-
Clone the Repository:
git clone https://github.com/WhiskyToad/fastapi-starter cd fastapi-starter
-
Configure Environment Variables:
Copy the .env.example file in the root of the project and configure your environment variables.
-
Build and Run the Docker Container:
docker compose up --build
-
Access the FastAPI App:
Open your browser and navigate to http://localhost:8000/docs to access the FastAPI Swagger documentation.
-
Stop the Docker Container:
docker-compose down
We use alembic for migrations, here are the commands that will need to be ran inside your docker terminal. When you make new models add them to the init file in the models folder to be picked up.
Make migration:
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head
Tests are all under the test folder and split into different folders within. It spins up a SQLite database for each test run and you can run the tests with the command
pytest