Skip to content

Fully working fastapi template with Tortoise ORM, alembic, pydantic models, emails and jwt authentication

Notifications You must be signed in to change notification settings

maicaballangan/fastapi-template

Repository files navigation

FastAPI Template

.
├── app
│   ├── core                        - core classes
│   ├── email-templates             - email templates
│   ├── models                      - tortoise models
│   │   ├── user.py
│   │   └── ...
│   ├── routes                      - api routers
│   │   ├── app_router.py
│   │   ├── auth_router.py
│   │   ├── user_routes.py
│   │   └── ...
│   ├── schemas                     - pydantic schema
│   │   ├── user_schemas.py
│   │   └── ...
│   ├── utils                       - utilities
│   └── main.py
├── tests
│   ├── models                      - model unit tests
│   ├── routes                      - integration tests
│   └── conftest.py
├── Dockerfile          
├── Makefile                        - build automation
└── README.md

Requirements

  • brew - Package Manager for macOS and Linux
  • make - Build automation tool for macOS and Linux
  • Python 3.11
  • uv Package Manager for python
  • Postgres
brew install make
brew install python@3.11
brew install uv
brew install postgresql

Development

Database Config

Install postgresql:

# Mac
brew install postgresql
brew services start postgresql

# Linux
sudo apt-get update
sudo apt-get install postgresql
sudo service postgresql start

Configure database:

createuser -s postgres
psql -U postgres -f data/create_superuser.sql

Setup

Note: See makefile for build automation commands

Create and activate virtual env:

make venv
source .venv/bin/activate

Copy env and add necessary variables:

cp .env.local .env

Install/sync dependencies:

make install

Run dev server with live reload:

make dev

Access

http://localhost:8001/docs

username: admin@test.com password: Admin12#

Testing

Run pytest:

make test

Coverage HTML

Run coverage report:

make coverage

Note: Make sure coverage is at least 90%

Lint Fix

Check and fix issues before you commit or else pre-commit hook will fail:

make lint

Other useful commands

To add a new dependency

uv add <dependency-name>

About

Fully working fastapi template with Tortoise ORM, alembic, pydantic models, emails and jwt authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published