A FastAPI mini application to learn how to use FastAPI with SQLAlchemy and PostGreSQL.
- Admin username: james
- Admin password: depend on your .env setup
- Create a virtual environment using
virtualenvmodule in python.
# Install module (globally)
pip install virtualenv
# Generate virtual environment
virtualenv --python=<your-python-runtime-version> venv
# Activate virtual environment
source venv/bin/activate
# Install depdendency packages
pip install -r requirements.txt- Configure
.envfile by creating a copy from.env.sample - Setup a postgres docker container
docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=<your-preferred-one> -d postgres:14- At
appdirectory, runalembicmigration command. Please make sure your postgres DB is ready and accessible. In case you want to useSQLiteinstead, please be sure to configure theenv.pyfile inalembicfolder to supportbatch executionsinceSQLitedoes not supportALTERcommand, which is needed to configure the foreign key and establish the indexes.
# Migrate to latest revison
alembic upgrade head
# Dowgragde to specific revision
alembic downgrade <revision_number>
# Downgrade to base (revert all revisions)
alembic downgrade base
# Create new revision
alembic revision -m <comment>- Run
uvicornweb server fromappdirectory (reloadmode is for development purposes)
uvicorn main:app --reload