Skip to main content

A CLI tool to bootstrap FastAPI applications with best practices

Project description

๐Ÿš€ fastinit - FastAPI Project Generator CLI

A powerful, production-ready CLI tool built with Typer that bootstraps FastAPI applications with best practices, database support, JWT authentication, and more.

โœจ Features

๐ŸŽฏ Project Initialization

  • One-command project setup with intelligent defaults
  • Interactive mode for guided configuration
  • Multiple Python version support (3.8+)

๐Ÿ—„๏ธ Database Integration

  • PostgreSQL, MySQL, and SQLite support
  • Pre-configured SQLAlchemy setup
  • Alembic migrations with automatic settings import from pydantic_settings
  • Database health checks included

๐Ÿ” JWT Authentication

  • PyJWT integration for token creation/verification
  • PyJWKClient support for remote JWK verification
  • Configurable JWKS endpoints
  • Protected route examples

๐Ÿ“ Logging & Configuration

  • Structured logging setup
  • Environment-based configuration with Pydantic Settings
  • .env file support

๐Ÿณ Docker Ready

  • Optimized Dockerfile
  • Docker Compose with database services

๐ŸŽจ Code Generation

  • Generate SQLAlchemy models
  • Generate service layers
  • Generate API routes
  • CRUD generators - create everything in one command

Installation

Install from source

pip install -e .

Install as a package (once published)

pip install fastinit

Install as dev dependency

pip install --dev fastinit

Usage

Initialize a new FastAPI project

# Basic project
fastinit init my-project

# With database support
fastinit init my-project --db

# With JWT authentication
fastinit init my-project --jwt

# With logging
fastinit init my-project --logging

# All features
fastinit init my-project --db --jwt --logging --docker

# Interactive mode
fastinit init my-project --interactive

Generate new components

# Generate a new model
fastinit new model User --fields "name:str,email:str,age:int"

# Generate Pydantic schemas (for request/response validation)
fastinit new schema User --fields "name:str,email:str,age:int"

# Generate a new service
fastinit new service UserService --model User

# Generate a new route/controller
fastinit new route users --service UserService

# Generate all at once (model + schema + service + route)
fastinit new crud User --fields "name:str,email:str,age:int"

# Generate with different pagination strategies
fastinit new crud Product --pagination cursor        # Cursor-based pagination
fastinit new route users --pagination none           # No pagination
fastinit new service UserService --pagination cursor # Custom pagination for service

Configuration Options

# Choose database type
fastinit init my-project --db --db-type postgresql
# Options: postgresql, mysql, sqlite

# Specify Python version
fastinit init my-project --python-version 3.11

Project Structure

my-project/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ health.py
โ”‚   โ”‚   โ””โ”€โ”€ deps.py
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”‚   โ””โ”€โ”€ security.py (if --jwt)
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ schemas/
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ””โ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ db/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ session.py (if --db)
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ Dockerfile (if --docker)

Examples

Basic FastAPI App

fastinit init my-api
cd my-api
pip install -r requirements.txt
uvicorn app.main:app --reload

Full-Featured App

fastinit init my-api --db --jwt --logging --docker
cd my-api
docker-compose up

Generate CRUD Components

cd my-api
fastinit new crud Product --fields "name:str,price:float,description:text"
# Creates:
# - app/models/product.py (SQLAlchemy model)
# - app/schemas/product.py (Pydantic schemas for validation)
# - app/services/product_service.py (Business logic)
# - app/api/routes/products.py (REST API endpoints)

๐Ÿ“š Documentation

๐Ÿ› ๏ธ Development

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

๐Ÿ“„ License

MIT License - see LICENSE for details

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

fastinit-0.2.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

fastinit-0.2.0-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file fastinit-0.2.0.tar.gz.

File metadata

  • Download URL: fastinit-0.2.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for fastinit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 67ea5fb6cde10fa7064b043641603297244f54098781d4382d961c41a403809d
MD5 526f3054b5f7d8c474e6a50d8a194d60
BLAKE2b-256 a984b4cecf431b3b0f9b58e5eb72a594f2ba35148f8bd4334c1a60bb9d44b572

See more details on using hashes here.

File details

Details for the file fastinit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fastinit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for fastinit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c5968b6eed14551d27b1f34c4664075f0a8cc935b4e71c2fc885bf5836a462d
MD5 9ae0dcd7aad1aaf81bce29c739f7ca3a
BLAKE2b-256 e7f6397778bbb49c3cea72b7e119c817ad2429a7496dd84929b8aaeac3bd3301

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