Base FastAPI project for applying general RestAPI Application cases.
- Minimal functionality.
- Convincing architecture.
- Easy to read.
- Compatibility.
- Versatility.
- user
- post [user (1 : n) post]
- tag [post (n : n) tag]
- Python3.9+
- Fastapi 0.78.0
- Database
- MySQL5.7+
- Migration with alembic
- pytest with real DB
- Load with two ways (eager, lazy)
- Modeling with schema (1:1, 1:n, n:n)
- dependency-injector
- service-repository pattern
- JWT authentication
- role separation each endpoint
- Deployment
- container environment(k8s, docker)
- raw WAS(Web Application Server)
- db(alembic)
alembic upgrade head
: apply every migrationsalembic downgrade base
: rollback every migrationsalembic revision --autogenerate -m "revision_name"
: create new migrationalembic history
: get alembic revision history
- How to migration
- Create or modify models from
app/model/*.py
alembic -x ENV=[dev|stage|prod] revision --autogenerate -m "revision_name"
- Check auto generated migration file from
app/migrations/versions/*.py
alembic -x ENV=[dev|stage|prod] upgrade head
If ENV does not exist, it will be applied to the test.
- Create or modify models from
- server
uvicorn app.main:app --reload
: base- options
- host:
--host 0.0.0.0
- port:
--port 8000
- host:
- test
pytest
: basepytest --cov=app --cov-report=term-missing
: coverage with stdoutpytest --cov=app --cov-report=html
: coverage with html
# mysql case
ENV=dev
DB=mysql
DB_USER=root
DB_PASSWORD=qwer1234
DB_HOST=localhost
DB_PORT=3306
# postgres case
ENV=dev
DB=postgresql
DB_USER=gyu
DB_PASSWORD=
DB_HOST=localhost
DB_PORT=5432