Skip to main content

You shall pass... your domain to transport! A Python codegen tool for transport layers in DDD, supporting most popular transport / API frameworks.

Project description

Gendalf

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

You shall pass... your domain to transport!

Gendalf is a Python code generation tool that simplifies the creation of transport layer code based on Domain-Driven Design (DDD) principles. With gendalf, you can effortlessly generate FastAPI, HTTPX, gRPC, aiohttp, and other transport framework code from your domain layer, ensuring that your business logic remains untouched while automating the generation of transport-related code.

Key Features

  • Domain-Driven Design (DDD) approach: Keeps your business logic in the domain layer and generates the transport layer automatically.
  • Multi-transport framework support: Supports FastAPI and HTTPX (next in line: gRPC; and more frameworks planned for future versions).
  • Powered by astlab generator: Uses Python's built-in Abstract Syntax Tree (AST) to generate Python modules from your domain entities and interfaces.

Why gendalf?

With gendalf, you don’t have to worry about manually wiring your domain logic to transport code. Whether you're building APIs, microservices, or handling complex asynchronous communication, gendalf automates the transport layer creation: handles repetitive and error-prone process of writing endpoint handlers and clients from scratch, letting you focus on what matters most: your business logic.

Target Audience

This tool is designed for Python developers working on services that follow the Domain-Driven Design (DDD) approach. It's particularly useful for:

  • Teams focusing on business logic without needing to handle the intricacies of APIs or transport layers.
  • Developers building Python API services.
  • Those looking for a way to streamline the development of API endpoints and client calls without the overhead of boilerplate code.

Comparison with existing codegen solutions

There are many tools for code generation in the Python ecosystem, but most are focused on simplifying specific tasks like serialization, or generating CRUD / REST operations. Here’s how gendalf project differs:

  • Domain-Driven Design (DDD) Focus: Unlike other code generation tools that focus on CRUD or specific transport protocols, this project fully integrates with a DDD approach. This means developers work on the domain layer and let the tool handle the presentation layer (API endpoints and clients).
  • Fully Automated Code Generation: The generated code for the server and client is complete and doesn’t require further modifications, saving time and reducing boilerplate.
  • Cross-Transport Flexibility: Currently, it supports FastAPI and HTTPX, but future versions will add gRPC support, allowing developers to generate code for various transport mechanisms without changing their domain logic.

E.g. grpcio-tools requires .proto files specification first and generates client stubs & server interface, so on the server side an additional code is required: implement request deserialization from protobuf python classes to domain (value objects), invoke domain layer and then serialize protobuf response.

Transports & frameworks

FastAPI & HTTPX

Run with gendalf gen src fastapi. It supports:

  • request-response (POST method, request & response in HTTP body in JSON format)
  • duplex streaming (WebSocket, requests & responses are in WS frames in JSON format)

What’s Generated

  • api/models.py: Pydantic models for requests and responses that mirror the domain objects.
  • api/client.py: Client classes with async methods, ready to make API calls with appropriate typings for request and response data.
  • api/server.py: Server handler classes, which include data serialization and domain logic invocation.

The generated code is complete, with no need for additional modifications.

Examples

gRPC (not supported yet)

This framework support is not supported yet.

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

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.1.0.tar.gz (18.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.1.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gendalf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ad54f8a7845f76eb8216a15bac83fbef5c9a306b2bb3c5d7272b4dc1d524f72
MD5 e35b6b01f4f28ae028767af530baaf50
BLAKE2b-256 01fea58fd4bc2018091bb034553176b3b81231469fe125e67815919485aae8a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for gendalf-0.1.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for gendalf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d62143fa710f14cf41301cc930925d0bfe415e9c3cfd2a8810fb9c3ea88a0fff
MD5 2aecc67d938b3c967fb27d3922af979d
BLAKE2b-256 e952828ae24379e9b42796e82fbfaa68acb14ddfcded5901519d199fddadecda

See more details on using hashes here.

Provenance

The following attestation bundles were made for gendalf-0.1.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