A FastAPI project.
Create a virtual environment and activate it:
- Windows:
py -3 -m venv venv
.\venv\Scripts\activate.bat
- Unix:
python3 -m venv venv
source ./venv/bin/activate
pip install "fastapi[all]"
pip freeze > requirements.txt
uvicorn app.main:app --reload
Swagger built-in at: http://localhost:8000/docs.
ReDoc built-in at: http://localhost:8000/redoc.
alembic init alembic
Configure alembic/env.py
.
alembic revision -m "create post table"
Fill in the upgrade()
and downgrade()
functions.
Apply the revision:
alembic current
alembic upgrade [REVISION_NUMBER]
Other commands:
alembic heads
alembic upgrade head
Downgrade:
alembic downgrade [REVISION_NUMBER]
alembic downgrade -1
Automatically generate features:
alembic revision --autogenerate -m "[MESSAGE HERE]"
Run tests with:
pytest
More verbose:
pytest -v
Print:
pytest -v -s
Disable warnings:
pytest --disable-warnings
Stop after first test failure:
pytest -x
Tutorial: from freeCodeCamp.