Skip to main content

Language-agnostic boilerplate generator from YAML data models

Project description

pati

PyPI Version Python 3.8+ License: MIT License: Apache 2.0

Language-agnostic boilerplate code generator from YAML data models and Jinja2 templates.

Define your data model once in YAML. Generate boilerplate code in any language (Java, Rust, Python, Go, TypeScript, etc.) using Jinja2 templates.

Why pati?

  • Single Source of Truth: Define your data model once, generate code for multiple languages
  • Template-Driven: Use Jinja2 to create language-specific templates
  • Configuration as Code: YAML schemas with anchors for DRY configuration
  • Language Agnostic: Generate Java, Rust, Python, Go, TypeScript, or any text-based format
  • Zero Runtime Dependencies: Just Python, PyYAML, and Jinja2

Quick Start

Installation

pip install patisserie

5-Minute Example

  1. Initialize a project:

    mkdir my-project && cd my-project
    pati init
    
  2. Edit your data model (.pati/schema.yaml):

    jobs:
      user_entity:
        template: entity.java.j2
        output: generated/User.java
        context:
          package: com.example
          class_name: User
          fields:
            - name: id
              type: Long
            - name: username
              type: String
    
  3. Customize a template (.pati/tmplts/entity.java.j2):

    package {{ package }};
    
    public class {{ class_name }} {
    {% for field in fields %}
        private {{ field.type }} {{ field.name }};
    {% endfor %}
    }
    
  4. Generate code:

    pati generate
    
  5. Check the output:

    cat generated/User.java
    

Features

๐Ÿ“‹ YAML Schema Support

  • Define jobs with template, output, and context
  • YAML anchors (&name) and aliases (*name) for reusable config
  • Merge key (<<: *alias) for DRY configuration
  • Full PyYAML support for complex structures

๐ŸŽจ Jinja2 Templates

  • Variables: {{ variable }}
  • Loops: {% for item in items %}
  • Conditionals: {% if condition %}
  • Filters: {{ value | filter }}
  • Complete Jinja2 feature set

๐Ÿ› ๏ธ CLI Tools

# Generate all jobs from default schema (.pati/schema.yaml)
pati generate

# Generate specific job(s) by name
pati generate pojo_user

# Generate jobs matching a glob pattern
pati generate 'pojo*'

# Generate jobs matching multiple patterns
pati generate 'pojo*' dto_user

# Generate from a specific schema
pati generate --config path/to/schema.yaml

# Dry run (preview without writing)
pati generate --dry-run

# Override output directory
pati generate --output-dir /path/to/output

# Initialize new project
pati init

# List available example templates
pati list

๐Ÿ“ฆ Built-in Examples

  • Java Spring Boot: Entities, DTOs, Repositories, Liquibase migrations
  • Rust SQLx: Models with SQLx derive macros
  • Python SQLAlchemy: ORM models
  • Go GORM: Struct definitions with GORM tags

Documentation

Example Use Cases

Multi-language ORM Models

jobs:
  user_java:
    template: entity.java.j2
    output: src/main/java/User.java
    context: { class_name: User, fields: [...] }
  
  user_python:
    template: model.py.j2
    output: models/user.py
    context: { class_name: User, fields: [...] }
  
  user_rust:
    template: model.rs.j2
    output: src/models/user.rs
    context: { struct_name: User, fields: [...] }

Microservice Scaffolding

Generate controllers, services, and DTOs from a single data model schema.

API Client/Server Code

Generate OpenAPI specs, request/response models, and route handlers.

Database Migrations

Generate SQL migrations, Liquibase changesets, or Flyway migrations.

Configuration Files

Generate Docker Compose, Kubernetes manifests, or Terraform code.

Architecture

schema.yaml          Template files              Generated code
     โ”‚               (Jinja2)                         โ”‚
     โ”‚                   โ”‚                            โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†’
                    pati
          (config loader + generator)
  1. Load YAML schema
  2. Extract job configuration
  3. Initialize Jinja2 environment
  4. Render each template with context
  5. Write generated files

Development

Setup

git clone https://github.com/yourusername/pati.git
cd pati
pip install -e ".[dev]"

Running Tests

pytest tests/ -v --cov

Building

./build.sh

Releasing

./release.sh 0.2.0

CLI Reference

# Generate from default schema
pati generate [JOB ...] [OPTIONS]
  JOB                     Job name(s) or glob patterns to run (default: all)
                          Examples: pojo_user  'pojo*'  'pojo*' dto_user
  --config, -c FILE       Path to schema file (default: .pati/schema.yaml)
  --dry-run               Show what would be generated without writing
  --output-dir DIR        Override output directory for all jobs

# Initialize new project structure
pati init [OPTIONS]
  --output, -o DIR        Output directory (default: current directory)

# List available example templates
pati list

# Show version
pati --version, -v

# Logging level (global flags, mutually exclusive)
pati --verbose COMMAND   # debug output
pati --quiet COMMAND     # warnings and errors only
pati -q COMMAND
pati --silent COMMAND    # errors only
pati -s COMMAND

# Show help
pati --help
pati COMMAND --help

Project Structure

pati/
โ”œโ”€โ”€ src/pati/           # Main package
โ”‚   โ”œโ”€โ”€ __init__.py          # Package metadata
โ”‚   โ”œโ”€โ”€ cli.py               # CLI entry point
โ”‚   โ”œโ”€โ”€ config.py            # YAML config loader
โ”‚   โ”œโ”€โ”€ generator.py         # Template generator
โ”‚   โ””โ”€โ”€ utils.py             # Helper functions
โ”œโ”€โ”€ examples/                # Example templates
โ”‚   โ”œโ”€โ”€ java-spring/
โ”‚   โ”œโ”€โ”€ rust-sqlx/
โ”‚   โ”œโ”€โ”€ python-sqlalchemy/
โ”‚   โ””โ”€โ”€ go-gorm/
โ”œโ”€โ”€ tests/                   # Test suite
โ”œโ”€โ”€ docs/                    # Documentation
โ”œโ”€โ”€ setup.py                 # Package metadata
โ”œโ”€โ”€ pyproject.toml          # Modern Python config
โ”œโ”€โ”€ build.sh                 # Build script
โ””โ”€โ”€ release.sh              # Release script

License

Licensed under either of:

at your option.

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for new features
  4. Ensure tests pass: pytest tests/ -v --cov
  5. Submit a pull request

Support

Roadmap

  • Watch mode for live template development
  • Template inheritance and includes
  • Custom Jinja2 filters and globals
  • Schema validation with JSON Schema
  • Plugin system for extensibility
  • Web UI for template editing
  • Template marketplace

Ready to generate? โ†’ Quick Start Guide

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

patisserie-1.0.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

patisserie-1.0.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file patisserie-1.0.0.tar.gz.

File metadata

  • Download URL: patisserie-1.0.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for patisserie-1.0.0.tar.gz
Algorithm Hash digest
SHA256 adafa481abaa87e18d1596b4815814d052ba293d86f01f4b39e5837f459ad24b
MD5 a85bb0c71688a0c503841d80a1c0b14a
BLAKE2b-256 01a1b158049d95b6e466bfb01d05e2307a574d23a67904067ea47a3dfa4f7767

See more details on using hashes here.

File details

Details for the file patisserie-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: patisserie-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for patisserie-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c5df91dee4d5e1bc4ffb42ee7e66c72ccfd18623d171e67a7d2933e1cf33d52
MD5 6467e94a5df0501c59a4c3aa99f6dfca
BLAKE2b-256 797ff7c96b7e71e482d1cdf850db93cd45e4e4726fd86162495858523185bb64

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