Template API with FastApi
Important
Min Python version: 3.12
Clone this repo:
git clone https://github.com/ezeparziale/fastapi-api-template
Create virtual environment:
python -m venv env
Activate environment:
- Windows:
. env/scripts/activate
- Mac/Linux:
. env/bin/activate
Upgrade pip:
python -m pip install --upgrade pip
Install requirements:
pip install -r requirements-dev.txt
Install pre-commit:
pre-commit install
Create .env
file. Check the example .env.example
🌐 Google Auth credentials:
Create your app and obtain your client_id
and secret
:
https://developers.google.com/workspace/guides/create-credentials
🔒 How to create a secret key:
openssl rand -base64 64
🚧 Before first run:
Run docker-compose
🐳 to start the database server
docker compose -f "compose.yaml" up -d --build adminer db
and init the database with alembic:
alembic upgrade head
🔑 Create a self-signed certificate with openssl:
openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
uvicorn app.main:app --reload --port 8000 --ssl-keyfile key.pem --ssl-certfile cert.pem
- Basic login
- Google Auth login
- Create users
- Examples endpoints CRUD
- Posts
- Users
- Votes
- API healthcheck
- JWT tokens
- Middlewares
- CORS
- Complete swagger Api info
- Postgres
Run linter and formatter
scripts/lint.sh
scripts/format.sh
Run coverage
coverage run -m pytest
coverage report --show-missing
coverage html
Or run all in one with:
scripts/coverage.sh
Run pytest with coverage
coverage run -m pytest
or
scripts/test.sh