π§© hexa β Type-Declared Dependency Injection for Python¶
hexa is a pattern and utility library for structuring complex hierarchical pipelines. It rests on one core idea: a concrete class's annotated slot type is the dependency decision. Variation is expressed entirely as class annotations β never as imperative wiring, never as __init__ parameters, never as a composition root that assembles objects by hand.
Doc model: this wiki is written for humans β howβto guides, examples, and testing recipes. The authoritative API contracts live in the code (docstrings) and the machineβreadable bundle under
docs/mcp/.
π Key Features¶
- 𧬠Three fixed layers β ABC contracts declare what a stage requires,
Impl*classes hold the shared default, bank-like specializations override only what differs - πͺ’
buildcontainer β recursively wires a full pipeline from__annotations__across the MRO;instances=andconfig=inject runtime values by name - π One neutral model β every converter serializes through a
PortNodetree; the model is not tied to any sample - π Interchangeable representations β
parse_yaml/generate_abc/parse_abc/generate_yamltranslate between YAML specs and ABC modules - β
Machine-checked agreement β
check_matchesverifies two representations describe the same tree and prints human-readable diffs - π₯οΈ Thin CLI β
hexa parse-yaml,parse-abc,generate-abc,generate-yaml,checkfor CLI workflows - π§ͺ Sample-driven tests β
samples/minimalandsamples/extraction_pipelinedouble as live examples for the test suite
π¦ Installation¶
From your internal PyPI:
Bash
pip install --extra-index-url https://$PYPI_USERNAME:$PYPI_PASSWORD@pip.aetoskia.com/simple hexa
From local source:
π Documentation Structure¶
| Section | Description |
|---|---|
| Overview | The mental model: three layers, two representations, and the container |
| Core Components | PortNode, MethodSpec, converters, check_matches, build, CLI |
| Use cases | Step-by-step recipes |
| Β· 01 β YAML first | Author a spec, generate ABCs, verify |
| Β· 02 β ABC first | Author the ABC module, emit a YAML spec |
| Β· 03 β Wiring & runtime | build, instances=, config= at runtime |
| Design | The extraction pipeline sample, port tree, and container algorithm |
| Philosophy | Why type-declared dependencies beats wiring by hand |
| Best Practices | Redundancy rules and the two fidelity guarantees |
| Error Handling | What can raise and what it means |
| Testing | Zero-mock unit testing against the samples |
π Related Resources¶
- Source Code: Gitea Repository
- Internal PyPI: pip.aetoskia.com/simple/hexa
- Drone CI: Auto-builds and publishes tagged releases, gated on black / ruff / mypy / pydoclint / pytest.
Β© Aetoskia Internal β hexa 0.1.0