- python >= 3.10.* and pip
- Create a virtual environment:
python3 -m venv venv
- Activate the created venv:
- Linux/Mac command:
source venv/bin/activate
- Windows Command:
.\venv\Scripts\activate
- Install dependencies (inside the venv from now on):
pip install -r requirements.txt
- Create a database.sqlite file (if using SQLite file)
Linux/Mac:
touch database.sqlite
Windows:
type NUL > database.sqlite
- Create a .env file
cp .env.sample .env
- Install pre-commit hooks:
pre-commit install
- Start the application:
invoke start
- Activate venv
- Linux/Mac command:
source venv/bin/activate
- Windows Command:
.\venv\Scripts\activate
- Start the application:
invoke start
Windows (requires PowerShell):
.\run
Note regarding alternative Windows start: App may not close with the terminal - make sure to terminate the app (CTRL
+ C
) before closing terminal.
- add new models' imports to the end of the models module file so that Alembic detects that new tables have to be created, like:
from models.user import User
- Generate a migration:
invoke migrationsGenerate --message=your_message_here
// or, if it throws an error on your machine (Windows especially),
// try using the direct alembic command:
alembic revision --autogenerate -m "your_message_here"
- Run migrations:
invoke migrationsRun
// or
alembic upgrade head
- Revert the last migration:
invoke migrationsRevert
// or
alembic downgrade -1
- https://fastapi.tiangolo.com/tutorial/sql-databases/
- https://medium.com/@tclaitken/setting-up-a-fastapi-app-with-async-sqlalchemy-2-0-pydantic-v2-e6c540be4308#:~:text=Improvements%20to%20the%20async%20experience,over%20a%20synchronous%20database%20setup.
- https://github.com/Youngestdev/fastapi-mongo
- https://github.com/zhanymkanov/fastapi-best-practices?tab=readme-ov-file#4-chain-dependencies