Skip to main content

PyArch

PyPI Python FastAPI Typer Jinja2 License: MIT Status

PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up the application structure, database, tests and Alembic, then lets you add CRUD modules and integrations without wiring every file by hand.

Unlike a one-time project template, PyArch keeps a small manifest in the generated project. Later commands use it to understand the project and update the right files.

PyArch CLI demo

Why PyArch?

PyArch removes repetitive setup while keeping the generated code readable and ready to change.

  • Layered FastAPI project structure
  • PostgreSQL and SQLite support
  • Complete CRUD modules with models, schemas, repositories, services and routes
  • GitHub Actions workflow for generated-project linting and tests
  • Automatic model and router registration
  • JWT auth integration with generated RSA keys
  • Protected CRUD routes
  • Alembic setup for relational databases
  • Tests and dependency setup through uv
  • Project-aware generation through pyarch.toml
  • Atomic project creation and rollback for failed extensions

v0.2.1 Highlights

  • Atomic project creation through a staging directory, with cleanup on failure
  • Rollback for failed module and auth generation
  • Docker Compose support for PostgreSQL projects
  • Refresh-token rotation protected against concurrent reuse on PostgreSQL
  • Self-tests for PyArch and an end-to-end generated-project workflow

Quick Start

PyArch requires Python 3.13 or newer and uv.

Install the latest release from PyPI:

pip install pyarch-cli

Create a project and move into it:

pyarch init my_project --database postgres
cd my_project

Copy .env.example to .env and set the database connection values. For a PostgreSQL project, initialize the database schema before starting the app:

pyarch db init

Start the generated application:

docker compose up -d

After a model change in a PostgreSQL project, generate and apply a reviewed revision and restart the application with:

pyarch db upgrade --message "describe schema change"

Without --message, PyArch prompts for one. When Alembic finds no metadata changes, db upgrade restarts Compose but creates no empty revision. Compose never runs migrations implicitly; migration files remain source code and should be reviewed and committed.

Safe Generation

pyarch init builds the project in a staging directory and publishes it only after all generation steps complete. If setup fails, the staging directory is removed. generate module and add integration track every affected file and restore the previous state if a generation step fails, including the manifest and dependency files.

Open http://127.0.0.1:8000/docs to use the generated Swagger UI.

You can now extend the project:

pyarch generate module user
pyarch add integration auth
pyarch generate module task --protected
pyarch info

Module names must be singular identifiers. PyArch derives the plural table and route names from them: use user to generate /users and the users table, not users.

What Gets Generated

A new project includes the application layers, database configuration, test setup and the files needed to run FastAPI:

my_project/
├── app/
│   ├── api/v1/
│   ├── core/
│   ├── db/
│   ├── dependencies/
│   ├── models/
│   ├── repositories/
│   ├── schemas/
│   ├── services/
│   └── main.py
├── tests/
├── alembic/          # PostgreSQL and SQLite only
├── .env.example
├── pyarch.toml
└── pyproject.toml

Each generated CRUD module adds:

  • a database model;
  • create, update and response schemas;
  • repository and service classes;
  • list, get, create, update and delete routes;
  • CRUD tests;
  • model and router registration in the existing application.

Commands

Command Description
pyarch init <name> Create a Layered FastAPI project
pyarch init <name> --database <engine> Select PostgreSQL or SQLite
pyarch generate module <singular-name> Add a CRUD module to the current project
pyarch add integration auth Add JWT authentication and user management
pyarch generate module <singular-name> --protected Generate protected CRUD routes
pyarch info Show the current project configuration
pyarch --help Show CLI help

Generation commands must be run inside a project created by PyArch.

Databases and Current Limitations

Database CRUD modules Alembic Auth integration Protected modules
PostgreSQL Yes Yes Yes Yes
SQLite Yes Yes Yes Yes

Current limitations:

  • only Layered Architecture is supported;
  • generated applications use synchronous database access;
  • SQLite projects run locally and do not include Docker Compose; pyarch db lifecycle commands are PostgreSQL-only. SQLite migrations can be run with Alembic directly;
  • generated projects are starter scaffolds and still require application-specific configuration and code;
  • the manifest format may change before a stable release.

Project Manifest

Every generated project contains pyarch.toml. It records the selected architecture and database, generated modules, enabled integrations and known project paths.

Commands such as generate module, add integration and info read this file instead of trying to infer project state from the directory structure. PyArch updates the manifest after a successful generation step.

Development

Clone the repository and install the development environment:

git clone https://github.com/Allcode-1/PyArch.git
cd PyArch
uv sync --group dev

Run the CLI from the checkout:

uv run pyarch --help

Or install the current checkout as an editable CLI tool:

uv tool install --editable .

Run the project checks before opening a pull request or releasing a version:

uv run pytest
uv run ruff check src tests
uv run mypy src tests
uv build

Architecture and Design

How PyArch is structured
Typer CLI
    ↓
Application services
    ↓
Generators
    ↓
Jinja2 templates
    ↓
Generated FastAPI project
    ↑
pyarch.toml

The CLI handles user input and delegates work to application services. Generators render Jinja2 templates and update files at explicit registration markers. The manifest provides the project context needed by later commands.

Why use a manifest?

Scanning the filesystem shows which files exist, but not which project choices produced them. The manifest stores those choices directly, so later commands do not have to guess the architecture, database or enabled features.

Why marker-based registration?

PyArch modifies files it generated itself. Explicit markers provide stable and readable insertion points for model and router imports without requiring a full AST rewriting pipeline.

Why Jinja2?

Templates stay close to the Python code users receive and can edit. Jinja2 is used with StrictUndefined, so missing template context fails during generation instead of producing incomplete files.

Roadmap

v0.2.1 (current)

  • singular module-name contract and corrected SQLite workflow documentation;
  • generated GitHub Actions workflow for linting and tests;
  • package and generated-manifest versions kept in sync.

v0.2.0

  • atomic project creation and cleanup on failure;
  • rollback for failed module and auth generation;
  • PostgreSQL Compose template and SQLite local setup;
  • self-test suite and generated-project integration coverage.

v0.3

  • Redis integration foundation;
  • opt-in cache-aside generation for CRUD modules;
  • dry-run mode.

Later

  • scheduler integration;
  • more architectures;
  • plugin system;
  • asynchronous database access.

Status

PyArch v0.2.1 is an early alpha release. The main workflow is usable, but commands, templates, generated code and the manifest may still change before a stable release.

Metadata

Release files for PyArch-CLI 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyArch-CLI 0.2.1
File Size Uploaded
pyarch_cli-0.2.1.tar.gz 236.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyArch-CLI 0.2.1
File Interpreter ABI Platform
pyarch_cli-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 284.9 kB

Release files / pyarch_cli-0.2.1.tar.gz

Download URL pyarch_cli-0.2.1.tar.gz
Size 236.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7d5f62efbc691f6a5c6424e497e8506c7fedb28cfbc22ab615b69be4d9352307
BLAKE2b-256 checksum
How to use checksums
07d46328a87167aac5714d78fbfda05516e41472dbad37fd0e9276eae506becf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pyarch_cli-0.2.1-py3-none-any.whl

Download URL pyarch_cli-0.2.1-py3-none-any.whl
Size 48.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
117f931dc6d8f140ba5d9fba4a2b13c7ab40204106a9b3a3168663e9fe5845f3
BLAKE2b-256 checksum
How to use checksums
d2ea571cfafe39c295d0b8f4e66e5355e3c4bc2df08701e87d7054e0016b3c50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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