Boilerplate for FastAPI
FastAPI docs Important
- Passwords are not actually getting hashed.
- All origins are allowed
- You might need to set
$PYTHONPATH
(to parentfolder of src, so where you cloned this repo to)
docker volume create postgres-data
for persistence of database- Create table
users
and dummydata: see scripts.py for simple function(s)- this can be done from either inside (Docker) container or from outside ofcourse.
pip install alembic
alembic init alembic
- set URL in alembic.ini (so probably
localhost:5432/
) - for
--autogenerate
, settarget_metadata
in alembicsenv.py
like this:
import sys
sys.path = ['', '..'] + sys.path[1:]
from src.database import Base
from src.database.models import User
target_metadata = Base.metadata
Tested on Python 3.7+
-
Create virtual env and activate it.
-
pip install -r requirements.txt
-
To run api:
uvicorn main:app
- optionally you can add
--reload
for watch functionality
- optionally you can add
- Make comment of/Remove the services of
api
andproxy
in docker-compose.yaml
docker volume create postgres-data
for persistence of databasedocker-compose up
to run db.
Change default configs in: