Tired of picking apart the wired container inside your data classes and services? wired_injector brings type-based dependency injection, plus a pipeline with operators, to your code.


Installation follows the normal Python packaging approach:

  $ pip install wired_injector

Quick Examples

Make an injectable factory:

class View:
    name: str = 'View'

You can then make an InjectorRegistry that scans for decorators:

    registry = InjectorRegistry()
    registry.scan()  # Look for decorators in/below current package

The inject can construct your instances. Maybe you need the container’s Settings:

class View:
    settings: Settings

Want to use NamedTuple instead of dataclass?

class View(NamedTuple):
    settings: Settings

Or perhaps functions instead?

def View(settings: Settings):
    site_name = settings.site_name
    name = f'View - {site_name}'
    return dict(name=name)

Use Annotated to give instructions to the injector, such as look up one type but expect a return value of another:

    settings: Annotated[MySettings, Get(BaseSettings)]

Use pipelines with operators – even custom – to narrow down the injection to the smallest surface area:

    site_name: Annotated[