/fastapi-template

A microservice project template using fastapi

Primary LanguagePythonMIT LicenseMIT

FastAPI assignment

This is a simple project to demonstrate the usage of FastAPI.

Features:

  • CRUD operations with PostgreSQL, Alembic and SQLAlchemy, Asyncio support.
  • FastAPI
  • Authentication with OAuth2 (Azure AD )
  • Unit tests
  • Docker Compose
  • Alembic migrations
  • CORS enabled
  • dotenv config
  • CI/CD with GitHub Actions
  • Dapr
  • Add one more service

Build dev environment with conda

conda env create --p ./.conda -f conda.yml
conda config --set env_prompt '({name})'
conda activate ./.conda

Bring the system up

You need run data migration first to make sure the database is ready.

Run via Docker Compose

docker-compose up -d --build

Run locally

pip install -r app/requirements.txt
uvicorn app.main:app --reload --port 8000

You can then open the website at http://localhost:8000

Migrate the data

alembic init -t async migrations
alembic revision --autogenerate -m "init"
alembic revision --autogenerate -m "add new tables"
alembic upgrade head

Tests

python -m pytest ./tests