Skip to content

ezeparziale/fastapi-api-template

Repository files navigation

⚡ Fastapi api template

Template API with FastApi

💾 Installation

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

🔧 Config

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

🏃 Run

uvicorn app.main:app --reload --port 8000 --ssl-keyfile key.pem --ssl-certfile cert.pem

📌 Features

  • Basic login
  • Google Auth login
  • Create users
  • Examples endpoints CRUD
    • Posts
    • Users
    • Votes
  • API healthcheck
  • JWT tokens
  • Middlewares
  • CORS
  • Complete swagger Api info
  • Postgres

🚨 Lint

Run linter and formatter

scripts/lint.sh
scripts/format.sh

🧑‍💻 Coverage

Run coverage

coverage run -m pytest
coverage report --show-missing
coverage html

Or run all in one with:

scripts/coverage.sh

🧪 Test

Run pytest with coverage

coverage run -m pytest

or

scripts/test.sh