Skip to main content

FastAPI Forge

PyPI version Python versions License

FastAPI Forge is a zero-runtime-dependency CLI that generates production-oriented FastAPI projects with PostgreSQL, Alembic migrations, JWT authentication, audit logging, and optional role-based access control (RBAC).

Generated features

  • Access and rotating refresh tokens, revocation, and session management
  • Password reset and email verification flows
  • PostgreSQL with sync and async SQLAlchemy sessions
  • Alembic migrations and an idempotent first-user seed command
  • Structured logs, request IDs, rate limiting, CORS, trusted hosts, and security headers
  • Liveness, readiness, and database health endpoints
  • A multi-stage, non-root Docker image and local Compose stack
  • Pytest tests, Ruff checks, and GitHub Actions CI

The RBAC variant adds hierarchical roles, permissions, per-user permissions, protected administration APIs, and RBAC seed data. The non-RBAC variant uses is_superuser for administrative authorization.

Requirements

  • Python 3.9+ for the generator
  • Python 3.12+ and PostgreSQL 14+ for generated applications
  • Docker with Compose v2 for the optional container workflow

Installation

Install or upgrade the CLI from PyPI:

python -m pip install --upgrade fastapi-forge-cli

The PyPI distribution is named fastapi-forge-cli because fastapi-forge is already used by another project. The installed terminal command remains fastapi-forge, and the Python import remains fastapi_forge.

Quick start

Generate a production-oriented FastAPI project with RBAC:

fastapi-forge create "Inventory API" --with-rbac
cd inventory-api

Run fastapi-forge --help to see all commands and fastapi-forge create --help to see every generation option.

Development installation

For development from a source checkout:

cd fastapi-forge
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .

For generator development, run pip install -e ".[dev]". On Windows PowerShell, activate with .venv\\Scripts\\Activate.ps1.

Generate a project

# With RBAC
fastapi-forge create "Inventory API" --with-rbac

# Without RBAC
fastapi-forge create "Inventory API" --without-rbac

# Select a parent directory
fastapi-forge create "Inventory API" --with-rbac --output-dir ./projects

The same generator is available as a Python library:

from pathlib import Path

from fastapi_forge import create_project

project = create_project(
    name="Inventory API",
    output_dir=Path("./projects"),
    with_rbac=True,
)
print(project)

Generation is staged before installation at the destination. Existing projects are preserved unless --force is explicitly supplied, and symbolic-link destinations are never replaced.

If neither RBAC option is supplied, an interactive terminal asks which variant to use. Non-interactive environments default to RBAC. Existing destinations are protected; --force permanently replaces the matching generated-project directory.

usage: fastapi-forge create [-h] [--output-dir OUTPUT_DIR]
                            [--with-rbac | --without-rbac] [--force]
                            name

Getting help

Discover available commands:

fastapi-forge --help

See every project-generation option:

fastapi-forge create --help

Print copy-ready examples:

fastapi-forge examples

Common commands include:

fastapi-forge create "Inventory API" --with-rbac
fastapi-forge create "Public API" --without-rbac
fastapi-forge create "Billing API" --with-rbac --output-dir ./projects

Run a generated project

Python

Create the PostgreSQL database described by sample.env, then:

cd inventory-api
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
cp sample.env .env
alembic upgrade head
python scripts/seed_first_user.py \
  --email admin@example.com \
  --password 'ChangeMe123!' \
  --full-name 'System Administrator'
uvicorn app.main:app --reload

Open http://localhost:8000/docs. Run pytest and ruff check . before committing.

Docker

cd inventory-api
cp sample.env .env
docker compose up --build

In another terminal:

docker compose exec api python scripts/seed_first_user.py \
  --email admin@example.com \
  --password 'ChangeMe123!' \
  --full-name 'System Administrator'

The Compose file is for local development; it uses development credentials and a bind mount.

Production deployment checklist

  1. Set APP_ENV=production.
  2. Supply a unique SECRET_KEY of at least 32 characters from a secret manager.
  3. Set explicit ALLOWED_HOSTS and HTTPS ALLOWED_ORIGINS values.
  4. Use managed PostgreSQL credentials and PG_SSLMODE=require, verify-ca, or verify-full.
  5. Configure Redis when rate limits must be shared across replicas.
  6. Configure SMTP and FRONTEND_URL for account emails.
  7. Run alembic upgrade head as one release job before starting new replicas.
  8. Terminate TLS at a trusted load balancer or reverse proxy.
  9. Send stdout/stderr to centralized logging. Enable file logs only with persistent storage.
  10. Monitor /api/v1/health/live and /api/v1/health/ready.
  11. Back up PostgreSQL, test restores, rotate secrets, and define rollback procedures.

Production mode refuses startup with a default/short secret, wildcard hosts or origins, or a non-TLS database mode. Interactive API documentation is disabled.

docker build -t inventory-api:1.0.0 .
docker run --rm --env-file .env inventory-api:1.0.0 alembic upgrade head
docker run --rm --env-file .env -p 8000:8000 inventory-api:1.0.0

Do not run migrations independently from every application replica.

Generator development and release

pytest
python -m build
python -m twine check dist/*

Review generated output from both variants whenever templates change.

License

MIT

Metadata

Release files for fastapi-forge-cli 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-forge-cli 0.1.2
File Size Uploaded
fastapi_forge_cli-0.1.2.tar.gz 99.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-forge-cli 0.1.2
File Interpreter ABI Platform
fastapi_forge_cli-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 247.0 kB

Release files / fastapi_forge_cli-0.1.2.tar.gz

Download URL fastapi_forge_cli-0.1.2.tar.gz
Size 99.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ea7499c60916ba9754f6120ffe5ac1fe26a557509f98de66a7c538e61a5de99e
BLAKE2b-256 checksum
How to use checksums
2a5bd1a4167831a924bf7846e4725262b3d7065e06ceefd74933be22b172e6c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release files / fastapi_forge_cli-0.1.2-py3-none-any.whl

Download URL fastapi_forge_cli-0.1.2-py3-none-any.whl
Size 147.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c704e64fbed3cc5c288ececd6261b9d36c828fef0a467f21eff2d3754e81bf9
BLAKE2b-256 checksum
How to use checksums
912f15a0150bc22d6363bbce97e19f63b3438ad87bde90521d436760d2e484bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page