Skip to main content

A powerful CLI tool to scaffold production-ready FastAPI projects with flexible database, auth, broker, and deployment options.

Project description

⚡ fastapi-spawn

The most complete FastAPI project scaffolding CLI — built for modern Python development.

PyPI version Python License: MIT CI

Generate production-ready FastAPI projects in seconds — with exactly the stack you need.


Installation

pip install fastapi-spawn
# or
uv pip install fastapi-spawn

Quick Start

# Interactive TUI — guided step-by-step
fastapi-spawn new my-api

# One-liner with all flags
fastapi-spawn new my-api \
  --db postgresql \
  --orm sqlalchemy \
  --migration alembic \
  --auth jwt \
  --broker redis \
  --storage s3 \
  --ai openai \
  --monitoring sentry \
  --email sendgrid \
  --log-dest cloudwatch \
  --vector-db qdrant \
  --stack full \
  --ci github

# Preview file tree without writing
fastapi-spawn new my-api --dry-run

# Add a feature to an existing project
fastapi-spawn add openai
fastapi-spawn add alembic
fastapi-spawn add sentry

What Gets Generated

my-api/
├── app/
│   ├── api/
│   │   └── v1/
│   │       ├── health.py        # GET /health  /readiness  /liveness
│   │       └── auth.py          # POST /auth/login  /auth/refresh
│   ├── core/
│   │   ├── config.py            # Pydantic Settings v2 — individual env fields + @property URLs
│   │   ├── logger.py            # Context-var logger — request ID, client IP, dual-timezone
│   │   ├── exceptions.py        # Custom exception hierarchy + handlers
│   │   ├── security.py          # JWT / bcrypt
│   │   ├── storage.py           # AWS S3 / MinIO helpers
│   │   ├── ai.py                # OpenAI / Anthropic / Gemini / Ollama async client
│   │   ├── email.py             # SendGrid / SMTP / SES
│   │   └── monitoring.py        # Sentry init / Prometheus metrics
│   ├── middleware/
│   │   ├── request_logger.py    # X-Request-ID, response time, structured logs
│   │   └── rate_limit.py        # slowapi — 429 with Retry-After
│   ├── db/
│   │   └── session.py           # Async SQLAlchemy / Tortoise / Beanie
│   ├── models/
│   ├── schemas/
│   ├── services/
│   └── repositories/
├── tasks/                       # Celery workers (root-level)
│   ├── celery_app.py
│   └── sample_tasks.py
├── migrations/                  # Alembic (async-compatible)
│   ├── env.py
│   └── versions/
├── infra/
│   ├── docker/
│   ├── helm/
│   └── terraform/
├── tests/
├── logs/                        # Local log rotation directory
├── main.py                      # uv run main.py
├── alembic.ini
├── Dockerfile                   # Uses uv for fast layer-cached builds
├── docker-compose.yml           # All selected services pre-configured
├── .env                         # gitignored
├── .env.example
├── .gitignore
├── .pre-commit-config.yaml
├── Makefile
└── pyproject.toml               # uv-compatible with [tool.uv.scripts]

All Options

fastapi-spawn new [OPTIONS] PROJECT_NAME

Database & ORM
  --db           postgresql | mysql | mongodb | sqlite | none
  --orm          sqlalchemy | tortoise | beanie | none
  --migration    alembic | aerich | none

Auth & Security
  --auth         jwt | oauth2 | api-key | none

Messaging & Cache
  --broker       redis | rabbitmq | kafka | none
  --cache        redis | memcached | none

Storage
  --storage      s3 | local | none          (s3 = AWS S3 or MinIO)

AI / LLM
  --ai           openai | anthropic | gemini | ollama | none

Monitoring
  --monitoring   sentry | prometheus | both | none

Email
  --email        sendgrid | smtp | ses | none

Notifications
  --notify       slack | discord | none

Logging
  --log-lib      loguru | structlog | standard
  --log-dest     local | cloudwatch | datadog | none

Vector Database
  --vector-db    qdrant | pinecone | elasticsearch | none

Deployment
  --stack        minimal | standard | full
  --ci           github | gitlab | both | none

Flags
  --no-docker    Skip Docker files
  --no-tests     Skip test suite
  --dry-run      Preview file tree without writing
  --force / -f   Overwrite existing directory
  --output / -o  Output directory

uv run Scripts

Every generated project has [tool.uv.scripts] pre-wired:

uv run dev        # uvicorn --reload
uv run start      # python main.py
uv run test       # pytest --cov
uv run lint       # ruff check
uv run format     # ruff format
uv run typecheck  # mypy
uv run migrate    # alembic upgrade head  (if alembic)
uv run rollback   # alembic downgrade -1  (if alembic)
uv run makemig    # alembic revision --autogenerate  (if alembic)
uv run worker     # celery worker  (if broker)
uv run beat       # celery beat    (if broker)

Environment Variables

Individual fields per service — no URL strings. URLs are assembled via @property:

ENVIRONMENT=dev
SECRET_KEY=super-secret-change-in-production

# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=my_api_db

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0

# AWS S3 (or MinIO — set ENDPOINT_URL for local)
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG
AWS_REGION=us-east-1
AWS_S3_BUCKET=my-api-bucket
AWS_S3_ENDPOINT_URL=http://localhost:9000   # MinIO local

# OpenAI (supports custom base URL for Azure / LM Studio)
OPENAI_API_KEY=sk-placeholder
OPENAI_MODEL=gpt-4o
OPENAI_BASE_URL=

# Sentry
SENTRY_DSN=https://xxx@sentry.io/yyy

# Logging
LOG_LEVEL=INFO
LOG_DIR=logs
LOG_BACKUP_DAYS=30

Add Features to Existing Projects

fastapi-spawn add sentry      # Sentry error tracking setup
fastapi-spawn add openai      # OpenAI async client + env vars
fastapi-spawn add alembic     # Alembic async migrations
fastapi-spawn add s3          # AWS S3 / MinIO storage utils
fastapi-spawn add celery      # Celery worker + tasks/
fastapi-spawn add helm        # Helm chart in infra/helm/
fastapi-spawn add terraform   # Terraform scaffold in infra/terraform/

ORM ↔ Database Compatibility

ORM Compatible Databases
sqlalchemy postgresql, mysql, sqlite
tortoise postgresql, mysql, sqlite
beanie mongodb
none any

Middleware Stack (always included)

Middleware What it does
RequestLoggingMiddleware Logs → METHOD /path + ✓ status duration with request ID
RateLimitMiddleware 200 req/min default via slowapi, returns 429 + Retry-After
CORSMiddleware Configurable via CORS_ORIGINS env var

Every response includes X-Request-ID and X-Response-Time headers.


Contributing

git clone https://github.com/Bishwajitgarai/fastapi-spawn
cd fastapi-spawn
uv sync --all-extras
uv run pytest

License

MIT © Bishwajit Garai

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_spawn-0.3.0.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_spawn-0.3.0-py3-none-any.whl (66.5 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_spawn-0.3.0.tar.gz.

File metadata

  • Download URL: fastapi_spawn-0.3.0.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for fastapi_spawn-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8a460a2faa9ad0a03fabdcca1c29a1b2bac7132383b5c53db0f47604855c2856
MD5 6efe5ce0b265a652e894370b3cce3739
BLAKE2b-256 89030322e8113c26478cb2151708bd99a8dd5fd864016bf4daf15ac49459e319

See more details on using hashes here.

File details

Details for the file fastapi_spawn-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_spawn-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 66.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for fastapi_spawn-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e917c0fdb22bd0118ae47c88dda8b1d790103b7d0051699e7da67e98d5c75741
MD5 05f038902c918c7709c8bd3026005551
BLAKE2b-256 27771566f00be38c5c03044973d0486021f30da12296d2e68fa5a311c5a2058c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page