Skip to main content

A Python codegen tool for transport layers in DDD, supporting most popular transport / API frameworks.

Project description

Gendalf Logo

Latest Version Python Supported Versions MyPy Strict Test Coverage Downloads GitHub stars

You shall pass... your code to adapters!


Gendalf is a code-first generator for Python adapters.

It generates type-safe transport and persistence layers directly from existing Python code and SQL files — without requiring OpenAPI, Protobuf, AsyncAPI, or ORMs.

Your code is the source of truth.
Gendalf generates the glue.


Key ideas

  • Code-first

    • Adapters are generated from Python modules and SQL files
    • No external specs to write or maintain
  • Deterministic

    • Gendalf uses a deterministic, AST-based algorithm to analyze code and generate adapters
    • It does not use LLMs or any probabilistic generation
    • Given the same inputs, the output is always identical
  • Adapter-oriented

    • Transport adapters: FastAPI servers, HTTP clients, gRPC, WebSockets
    • Persistence adapters: SQL → typed Python APIs
    • Boundary code only — business logic remains untouched
  • Type-safe

    • Python types propagate across generated code
    • SQL queries produce typed inputs and outputs
  • Minimal opt-in

    • Use standard Python type annotations
    • Mark Python classes intended as entrypoints with @entrypoint
    • Add -- sqlcast markers to SQL files
    • Everything else is inferred

Why Gendalf

Most code generators require you to:

  • write specs first,
  • duplicate models,
  • adopt specific frameworks or ORMs.

LLM-based code generation introduces other problems:

  • non-deterministic output,
  • mandatory manual review,
  • runtime cost and token usage.

Gendalf does the opposite:

  • Python code defines the contract,
  • SQL defines persistence,
  • adapters and DTOs are generated by explicit algorithms (type inspection and AST traversal).

Generated code can be committed, regenerated in CI, and treated as compiler output.


Transports

FastAPI & HTTPX

Run with gendalf src cast fastapi.

Supported patterns:

  • request-response (POST, JSON body)
  • duplex streaming (WebSocket, JSON frames)

Generated code

  • src/api/fastapi/models.py — Pydantic request/response models
  • src/api/fastapi/client.py — async typed HTTP client
  • src/api/fastapi/server.py — server handlers with serialization and domain invocation

Generated code is complete and requires no manual edits.

Aiohttp

Run with gendalf src cast aiohttp.

Supported patterns:

  • request-response (POST, JSON body)
  • duplex streaming (WebSocket, JSON frames)

Generated code

  • src/api/aiohttp/models.py
  • src/api/aiohttp/client.py
  • src/api/aiohttp/server.py

Examples

gRPC (planned)

Not supported yet.

Planned:

  • unary-unary
  • unary-stream
  • stream-unary
  • stream-stream

Persistence

SQL

WIP: Generate type-safe Python APIs directly from SQL files — no ORM required.

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

gendalf-0.4.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

gendalf-0.4.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file gendalf-0.4.0.tar.gz.

File metadata

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

File hashes

Hashes for gendalf-0.4.0.tar.gz
Algorithm Hash digest
SHA256 77fbb9d79260eb4ce4899513f92a4c7fe714d4053d5f0be32158df93201beaa4
MD5 693eee76248280cfeff1d909a2c00ab1
BLAKE2b-256 f22a3c41eca381ba6d6a89e56ed01c32d527b3b30662ecd83e2b05607a5822fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for gendalf-0.4.0.tar.gz:

Publisher: publish.yaml on zerlok/gendalf

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

File details

Details for the file gendalf-0.4.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for gendalf-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e36586c7808a01b9f5f826364e0b0974ed77a667eaf0db453d9316716928b84c
MD5 45470c369cd876808dfa167c4d890daa
BLAKE2b-256 fc6a638522dba0aa35286bfa411a501f9944cf19c4a41c676d222aba0d6c0b1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gendalf-0.4.0-py3-none-any.whl:

Publisher: publish.yaml on zerlok/gendalf

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