Skip to main content

modwire-hex

Explicit dependency-injection conventions for hexagonal Django applications, built on Wireup.

Install

pip install modwire-hex

The framework keeps the container at the composition root. Domain and application code use ordinary, type-annotated constructor dependencies.

Domain code may use DomainError for business-rule failures. It must not contain HTTP status codes, response shapes, Django types, or DI concerns.

from modwire_hex import DomainError


class OrderCannotRequestCredit(DomainError):
    pass
from modwire_hex import Containers, Module, Providers


class Payments:
    def charge(self, amount: int) -> None: ...


class StripePayments(Payments):
    def charge(self, amount: int) -> None:
        ...


class PlaceOrder:
    def __init__(self, payments: Payments) -> None:
        self.payments = payments


orders = Module(
    "orders",
    providers=[
        Providers.service(PlaceOrder, None),
        Providers.bind(Payments, StripePayments, "singleton", None),
    ],
)

container = Containers.create_sync((orders,), None)
with container.enter_scope() as scope:
    place_order = scope.get(PlaceOrder)

See ADR 0001 for the architecture, conventions, and delivery sequence.

Django integration

Compose a Django process through one explicit application object:

from modwire_hex import DjangoApplication

from .orders.wiring import orders


application = DjangoApplication(modules=(orders,))

Configure the framework and its Ninja Extra API in Django settings:

INSTALLED_APPS = [
    "modwire_hex.django.apps.ModwireConfig",
]

MIDDLEWARE = [
    "modwire_hex.django.middleware.RequestScopeMiddleware",
]

MODWIRE = {
    "APPLICATION": "myproject.wiring:application",
    "NINJA": {"title": "My Project API", "version": "1.0.0"},
}

Mount the framework API once. Ninja Extra discovers controllers from installed HTTP adapter apps:

from django.urls import path

from modwire_hex.django import DjangoNinja


urlpatterns = [path("api/", DjangoNinja.api().urls)]

At an HTTP boundary, resolve only use cases from the active request scope:

from modwire_hex.django import DjangoRequest


place_order = DjangoRequest.resolve(request, PlaceOrder)

DjangoRepository is a base for outbound adapters. It centralizes generic load and create-or-update persistence mechanics; each context repository owns its key, lookup, record mapping, and absence semantics.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modwire_hex-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

modwire_hex-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for modwire_hex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4e33a8f557916aa69dd8cef6da70fd1b4991cf680d6670cd816435917510b90
MD5 300bf4578afde43f96a4b2470716f86b
BLAKE2b-256 8533e172d21bab326d2f47d8c78aca4025541c655d2d42a6cab6a089e49aff1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for modwire_hex-0.1.0.tar.gz:

Publisher: release.yml on modwire/modwire-hex

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

File details

Details for the file modwire_hex-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for modwire_hex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb39787c2ca606a6f4dc3d9488370a3b3405787e848424417c5c3cbdebb84e74
MD5 bd87ed2929661edcd0715904c5aa835c
BLAKE2b-256 7f0d81a1ec56d941ce65f934d6c7ee66c72012a0f4ddcc5a4497f3f046da0330

See more details on using hashes here.

Provenance

The following attestation bundles were made for modwire_hex-0.1.0-py3-none-any.whl:

Publisher: release.yml on modwire/modwire-hex

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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