Skip to main content

A CLI to generate a FastAPI + Alembic + SQLAlchemy boilerplate

Project description

Animated_Logo_GIF_Creation-ezgif com-video-to-gif-converter

The high-performance, drift-ready boilerplate for FastAPI.

Hatchback is a powerful CLI tool designed to bootstrap and manage production-ready FastAPI applications. It comes pre-loaded with best practices, security hardening, and a modular architecture that scales.

โœจ Features

  • ๐Ÿš€ Production Ready: SQLAlchemy 2.0, Pydantic v2, and Alembic pre-configured.
  • ๐Ÿ›ก๏ธ Secure by Default: Rate limiting (SlowAPI), hardened Auth (JWT), secure secret generation, and non-root Docker containers.
  • โšก Blazing Fast: Optional uv support for lightning-fast dependency management.
  • ๐Ÿ—๏ธ Clean Architecture: Service-Repository pattern for maintainable code.
  • โœ… Testing Ready: Integrated pytest setup with hatchback test.
  • ๐Ÿณ Dockerized: Ready-to-deploy docker-compose setup with healthchecks.
  • ๐ŸŽ๏ธ Drift Mode: A CLI that drives as good as it looks.

๐Ÿ“ฆ Installation

pip install hatchback

๐Ÿ Quick Start

1. Initialize a new project

hatchback init my_project_name

You will be prompted for:

  • Database Name
  • Docker inclusion
  • uv usage (if installed, for faster setup)

Options:

  • --use-uv: Force usage of uv for virtualenv creation.
  • --no-docker: Skip Docker file generation.

2. Start the Engine

Before hitting the gas, ensure your database is running and the schema is initialized.

1. Start Database:

cd my_project_name
docker-compose up -d db

(Or configure a local Postgres instance in .env)

2. Initialize Database: Create and apply the first migration for the built-in models (User, Tenant).

hatchback migrate create -m "initial_setup"
hatchback migrate apply

3. Run Server: Start the development server with hot-reloading.

hatchback run

๐ŸŽ‰ Success! Your API is now live.

3. Scaffold Resources

Don't write boilerplate. Generate Models, Schemas, Repositories, Services, and Routes in one go. Hatchback automatically registers your new routes and services, so they are ready to use immediately.

hatchback make Product

4. Manage Migrations

Wrapper around Alembic to keep your database in sync.

# Create a migration
hatchback migrate create -m "add products table"

# Apply migrations
hatchback migrate apply

5. Seed Data

Populate your database with initial data (default tenant and admin user).

hatchback seed

6. Import Existing Database

Have an existing database? Hatchback can inspect it and generate your entire project architecture automatically.

# Output models only to a file
hatchback inspect --url postgresql://user:pass@localhost:5432/mydb --output app/models/legacy.py

# Full Scaffold Mode (Recommended)
# Generates Models, Services, Repositories, Schemas, and Routes for every table
hatchback inspect --scaffold --url postgresql://user:pass@localhost:5432/mydb

๐Ÿ—๏ธ Architecture Explained

Hatchback follows a Service-Repository pattern to keep your code modular and testable.

  1. Routes (app/routes/): Handle HTTP requests/responses and dependency injection. They delegate business logic to Services.
  2. Services (app/services/): Contain the business logic. They orchestrate data operations using Repositories.
  3. Repositories (app/repositories/): Handle direct database interactions (CRUD). They abstract the SQL/ORM details from the rest of the app.
  4. Models (app/models/): SQLAlchemy database definitions. hatchback test

Run with coverage (pass arguments to pytest)

hatchback test -- Hatchback projects come with pytest configured.

# Run all tests
pytest

# Run with coverage
pytest --cov=app

๐Ÿ“‚ Project Structure

my_project/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ config/       # Database, Security, Limiter config
โ”‚   โ”œโ”€โ”€ models/       # SQLAlchemy Database Models
โ”‚   โ”œโ”€โ”€ schemas/      # Pydantic Data Schemas
โ”‚   โ”œโ”€โ”€ repositories/ # Data Access Layer (CRUD)
โ”‚   โ”œโ”€โ”€ services/     # Business Logic
โ”‚   โ”œโ”€โ”€ routes/       # API Endpoints
โ”‚   โ”œโ”€โ”€ dependencies.py
โ”‚   โ””โ”€โ”€ main.py
โ”œโ”€โ”€ alembic/          # Database Migrations
โ”œโ”€โ”€ tests/            # Pytest Suite
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ requirements.txt

๐Ÿ›ก๏ธ Security Features

  • Rate Limiting: Built-in protection against brute-force attacks.
  • Secure Headers: Trusted host middleware configuration.
  • Password Hashing: Argon2/Bcrypt support via Passlib.
  • Docker Security: Runs as a non-root user to prevent container breakout.

Built with ๐Ÿ’– and ๐ŸŽ๏ธ by Ignacio Bares(nachovoss) and the Hatchback Team.

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

hatchback-0.1.8.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

hatchback-0.1.8-py3-none-any.whl (55.2 kB view details)

Uploaded Python 3

File details

Details for the file hatchback-0.1.8.tar.gz.

File metadata

  • Download URL: hatchback-0.1.8.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatchback-0.1.8.tar.gz
Algorithm Hash digest
SHA256 f88e53ef7bd533f8212055a69340e1ec7c094cba2e42def453fb9f6171ab0ff8
MD5 0a8643e7b1096b577aeaac7085d11342
BLAKE2b-256 32c77a1c73ffbf3c3bd99a70b33828bb3c1160c478f650a94508a94d317d79ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatchback-0.1.8.tar.gz:

Publisher: publish.yml on nachovoss/hatchback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hatchback-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: hatchback-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 55.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hatchback-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 96fdf7f62162ffd7507aab89c584a8e059c21606fa1040d503c4e0f2beea3070
MD5 a90484004480442460ec7a8750013bfb
BLAKE2b-256 91a701b5935ca53365d6404f8417c29fc4c4cdfe9d09cd37ab7ac2da7252aed4

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatchback-0.1.8-py3-none-any.whl:

Publisher: publish.yml on nachovoss/hatchback

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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