Overcomplicating and overengineering is really really bad! At the same time we need all the important elements for future expansion. Here comes this FastAPI boilerplate template.
This is as simple as any beginner can start with. At the same time it includes most of the important elements to be the easiest starting point for a strong FastAPI API project.
To start with it:
- Create a new project
mkdir project-name
cd project-name
- Clone the repo
git clone https://github.com/7shovon7/fastapi-sqlalchemy-alembic-websocket-template.git .
- Ensure that you don't have any of migration version files accidentally pulled from this repo
rm -rf migrations/versions/*
- Create virtual environment and install the dependencies (Consider choosing the right one - python or python3 and pip or pip3)
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
- Add
.env
file and update. - Update settings data in
api/config.py
.
- Change the
DATABASE_URI
value accordingly in.env
file. - If database type is not SQLite3, remove
connect_args
insideapi/database/__init__.py
file. - Put all the database table models (sqlalchemy models) inside
api/database/models.py
file. As theBase
variable ofmigrations/env.py
should come from the database tables file, so this is better for small or mid sized project. - Setup schemas independently inside public folders under each modules/apps.
Create migration
alembic revision --autogenerate -m 'Initial migration'
Apply migration
alembic upgrade head
python3 asgi.py