Skip to main content

FastScaff

FastAPI project scaffolding tool - quickly generate standardized FastAPI project structures.

中文文档

Installation

pip install fastscaff

Commands

Create Project

fastscaff new myproject --orm sqlalchemy

Options:

  • --orm - ORM choice: sqlalchemy or tortoise (default: tortoise)
  • --output - Output directory (default: current directory)
  • --with-rbac - Include Casbin RBAC support
  • --with-celery - Include Celery task queue support
  • --force - Overwrite existing directory

Examples:

# Basic project with SQLAlchemy
fastscaff new myproject --orm sqlalchemy

# Full-featured project
fastscaff new myproject --orm sqlalchemy --with-celery --with-rbac

# Specify output directory
fastscaff new myproject --output /path/to/dir

Generate Models from Database

Generate ORM models by introspecting existing MySQL database tables:

cd myproject
fastscaff models --db-url "mysql://user:pass@localhost:3306/mydb"

Options:

  • --db-url - Database connection URL (required)
  • --orm - Target ORM: sqlalchemy or tortoise (auto-detected from requirements.txt)
  • --tables - Comma-separated table names (default: all tables)
  • --output - Output directory (default: current directory)

Examples:

# In project directory - ORM is auto-detected
cd myproject
fastscaff models --db-url "mysql://root:password@localhost:3306/mydb"

# Generate models for specific tables
fastscaff models --db-url "mysql://..." --tables user,order,product

# Explicitly specify ORM
fastscaff models --db-url "mysql://..." --orm tortoise

Generated models include:

  • Field type mapping
  • Primary keys and auto-increment
  • Indexes
  • Foreign key relationships
  • Table and column comments

Project Structure

myproject/
├── app/
│   ├── main.py              # Application entry point
│   ├── core/
│   │   ├── config.py        # Settings (env-based)
│   │   ├── database.py      # Database connection
│   │   ├── redis.py         # Redis client
│   │   ├── security.py      # Password hashing, JWT
│   │   ├── logger.py        # Structured logging
│   │   └── lifespan.py      # Startup/shutdown events
│   ├── api/v1/
│   │   ├── router.py        # API router
│   │   └── endpoints/       # Route handlers
│   ├── models/              # ORM models
│   ├── schemas/             # Pydantic schemas
│   ├── repositories/        # Data access layer
│   ├── services/            # Business logic layer
│   ├── middleware/          # Request/response middleware
│   ├── exceptions/          # Custom exceptions
│   └── utils/               # Utility functions
├── tests/
├── .env.example
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── requirements.txt

Architecture

The generated project follows a layered architecture:

Layer Directory Responsibility
API api/ HTTP handling, request validation, response formatting
Service services/ Business logic, orchestration
Repository repositories/ Data access, database queries
Model models/ Database table definitions
Schema schemas/ Request/response data structures

Services are accessed via a singleton registry pattern:

from app.services import registry

user = await registry.user_service.get_user_by_id(user_id)

Built-in Features

Middleware

  • CORS handling
  • Request logging with trace ID
  • JWT authentication
  • Security headers
  • Request signing verification

Utilities

  • Snowflake ID generator
  • Rate limiter (Redis-based)
  • Cache decorator
  • Password hashing

Database

  • SQLite by default (zero configuration)
  • MySQL/PostgreSQL ready (just update DATABASE_URL)
  • Async database operations
  • Request-scoped sessions (SQLAlchemy)

Running the Project

cd myproject
pip install -r requirements.txt
make dev

The project runs immediately with SQLite - no database setup required.

Available make commands:

make dev          # Start development server
make test         # Run tests
make lint         # Run linter
make format       # Format code
make docker-up    # Start all services (Docker)
make docker-down  # Stop all services

If Celery is enabled:

make celery-worker  # Start Celery worker
make celery-beat    # Start Celery beat scheduler

Configuration

Configuration is managed via environment variables. Copy .env.example to .env:

# Application
ENV=dev
DEBUG=true
PORT=8000

# Database
DATABASE_URL=sqlite+aiosqlite:///./app.db
# DATABASE_URL=mysql+aiomysql://user:pass@localhost:3306/mydb

# Redis
REDIS_URL=redis://localhost:6379/0

# JWT
JWT_SECRET_KEY=your-secret-key
JWT_ACCESS_TOKEN_EXPIRE_MINUTES=30

# Celery (if enabled)
CELERY_BROKER_URL=redis://localhost:6379/1
CELERY_RESULT_BACKEND=redis://localhost:6379/1

Development

# Clone the repository
git clone https://github.com/lee-hangzhou/fastscaff.git
cd fastscaff

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Code formatting
ruff check --fix .
ruff format .

License

MIT

Download files

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

Source Distribution

fastscaff-0.2.4.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

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

fastscaff-0.2.4-py3-none-any.whl (67.3 kB view details)

Uploaded Python 3

File details

Details for the file fastscaff-0.2.4.tar.gz.

File metadata

  • Download URL: fastscaff-0.2.4.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.2

File hashes

Hashes for fastscaff-0.2.4.tar.gz
Algorithm Hash digest
SHA256 1df2d2c707842f490d2798097d4db017c8c0aada021638820b6211553dbba6b4
MD5 46d840982b0d9b07dc9eb641c8c76630
BLAKE2b-256 cfdb789de815acb4c399578606ec523807e2d6455087f08593bf1ea76896c503

See more details on using hashes here.

File details

Details for the file fastscaff-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: fastscaff-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 67.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.2

File hashes

Hashes for fastscaff-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ea78a73ce05d20e761be256b5de7de0f5a4c4865b7111940f2bacfe79f3539fe
MD5 9e0ea35d45fb1db1c5ec6adece008957
BLAKE2b-256 83615a790eb5e1d8e1dfc68759ae7f7079f584f2356754692b7e985b4afa9998

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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