Skip to main content

A CLI tool to scaffold FastAPI projects and modules (work in progress).

Project description

fastapi-maker

🚀 FastAPI project scaffolding CLI – Generate production-ready CRUD modules in seconds with explicit field requirements, realistic examples, and clean offline Swagger documentation.

A powerful command-line tool to bootstrap and scale FastAPI applications with a clean, maintainable architecture:

  • Auto-generated SQLAlchemy models with id, created_at, updated_at, and custom fields
  • Pydantic v2 DTOs (Create, Update, Response) with accurate type hints and validation
  • Repository + Service pattern for separation of concerns
  • Routers auto-registered in main.py with clean path parameters
  • Alembic pre-configured with models auto-imported
  • Offline API Documentation with Swagger UI and ReDoc (no CDN required)
  • Environment management via .env for example:
import os
from dotenv import load_dotenv

load_dotenv()

DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./app.db")
  • Self-documenting OpenAPI specs with clear required/optional field indicators

Perfect for rapid prototyping, MVP development, or enforcing consistent structure across engineering teams.


✨ Features

Core Commands

  • fam init → Initialize a new FastAPI project with database, Alembic, CORS, logging, and offline documentation
  • fam create <entity> [fields...] → Generate a full CRUD module with customizable fields
  • fam migrate [-m "message"] → Auto-generate and apply database migrations with Alembic

🛡️ Offline API Documentation

  • Zero CDN dependencies - All Swagger UI and ReDoc assets served locally
  • Privacy-focused - No external network requests for documentation
  • Fast loading - Documentation works without internet connection
  • Customizable - Easy to configure themes and favicons
  • Powered by fastapi-standalone-docs - Visit for advanced configuration options

Smart Field Definition Syntax

Define required vs optional fields using intuitive syntax:

fam create user *name:str email:str age:int is_active:bool
  • *name:strrequired field (name must be provided)
  • email:stroptional field (email can be omitted)

Supported Field Types

Type SQL Type Pydantic Type Example Value
str String(255) str "John Doe"
text Text str "A detailed description…"
int Integer int 42
bigint BigInteger int 9007199254740991
float Float float 3.14
bool Boolean bool true
date Date date "2023-10-05"
datetime DateTime datetime "2023-10-05T14:30:00"
email String(255) str "user@example.com"
url String(255) str "https://example.com"

Auto-Generated Module Structure

app/api/user/
├── user_model.py        # SQLAlchemy ORM model with nullable rules
├── user_repository.py   # CRUD database operations
├── user_service.py      # Business logic and DTO mapping
├── user_router.py       # FastAPI routes (auto-registered in main.py)
└── dto/
    ├── user_in_dto.py   # Input validation (Create)
    ├── user_update_dto.py # Partial updates (Patch)
    └── user_out_dto.py  # API responses (with id, created_at, updated_at)

Production-Ready Swagger (OpenAPI) Docs

  • Clean route display: /users/{user_id} instead of /users/user_id
  • Clear field requirements: POST endpoint description lists Required and Optional fields
  • Realistic examples: Type-specific values ("user@example.com", 42, true) instead of generic placeholders
  • Full visibility: All fields appear in schema documentation, even optional ones
  • Accurate nullability: Optional fields correctly marked as nullable in responses
  • Offline functionality: Documentation works completely offline using local assets

Database Support & Migrations

  • Multi-database support: SQLite, PostgreSQL, and MySQL
  • Auto-database creation: Automatically creates database if it doesn't exist
  • Smart migrations: Alembic configured with environment-based settings
  • SQLite compatibility: Proper handling of autoincrement primary keys

Safe Data Handling

  • OutDTOs accept None for optional fields → prevents validation errors when DB returns NULL
  • Always includes datetime import in OutDTOs for created_at/updated_at
  • Parameter name consistency → no more NameError: name 'xxx_data' is not defined

📦 Installation

pip install fastapi-maker

🚀 Quick Start

# Initialize a new project with offline documentation
fam init

# Create a User entity with required name and optional fields
fam create user *name:str email:str age:int is_active:bool

# Create an Animal entity with only a required name
fam create animal *name:str

# Run database migrations (auto-creates database if needed)
fam migrate -m "Add user and animal tables"

# Start your FastAPI app with offline documentation
python3 -m app.main

Then visit http://localhost:8000/docs to see your auto-generated, fully-documented API - completely offline!


🔧 Advanced Configuration

Offline Documentation Customization

The generated project uses fastapi-standalone-docs for offline documentation. You can customize it in app/main.py:

from fastapi_standalone_docs import StandaloneDocs

app = FastAPI()

# Basic configuration (included by default)
StandaloneDocs(app=app)

# Advanced configuration
StandaloneDocs(
    app=app,
    redoc_favicon_url="/custom-favicon.png",  # Custom favicon
    swagger_favicon_url="/custom-favicon.png",
    with_google_fonts=True,  # Enable Google Fonts (disabled by default)
)

Database Configuration

Supported database URLs in your .env file:

# SQLite (default)
DATABASE_URL=sqlite:///./app.db

# PostgreSQL
DATABASE_URL=postgresql://user:password@localhost:5432/mydatabase

# MySQL
DATABASE_URL=mysql://user:password@localhost:3306/mydatabase

🎯 Use Cases

  • Rapid Prototyping: Go from idea to working API in minutes
  • MVP Development: Perfect for startups and hackathons
  • Team Consistency: Enforce clean architecture across engineering teams
  • Learning FastAPI: Excellent for understanding FastAPI best practices
  • Production APIs: Solid foundation for scalable applications

🤝 Contributing

We welcome contributions! Feel free to:

  • Report bugs and suggest features
  • Submit pull requests
  • Improve documentation
  • Share your use cases

📄 License

MIT License - feel free to use in commercial projects.


💡 Pro Tip: Use * prefix to mark fields as required — everything else is optional by default. Your API consumers will thank you for the clarity!

🌐 Documentation Note: Your API docs work completely offline thanks to fastapi-standalone-docs. Perfect for development in restricted environments or when privacy matters!

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_maker-0.2.2.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

fastapi_maker-0.2.2-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_maker-0.2.2.tar.gz.

File metadata

  • Download URL: fastapi_maker-0.2.2.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for fastapi_maker-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0ed314a1b3c7964f757819e7727cc03cb48f41397fdeae2e0614a8d61683767c
MD5 94a8b1b112ae65cfc1f3bbfb14c3834d
BLAKE2b-256 afcf8dbf4d9824edfd76f675f78b0152a3002fee4b36b80c9232f4a697856c9c

See more details on using hashes here.

File details

Details for the file fastapi_maker-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: fastapi_maker-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for fastapi_maker-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c2a2cf47bd55bf88d660f0aa01c6488b960b05ba2effb70bfd9fb98abe75af09
MD5 efd9a4042561eac8b4c8b7a184e8d7b5
BLAKE2b-256 d5bcc00eabbc21e3350d9ba0f96c158e00d3215e2a2011230dd5f7c67263411b

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