Show: Wireup - Modern Dependency Injection for Django

Hi Django, Wireup is a performant, concise, and easy-to-use dependency injection container for Python and Django.

It allows you to register services and configuration which will then be automatically injected by the container when requested.

Key wireup features:

Feature Description
:arrow_heading_down: Dependency Injection Inject services and configuration using a clean and intuitive syntax.
:gear: Autoconfiguration Automatically inject dependencies based on their types without additional configuration for the most common use cases.
:scroll: Interfaces / Abstract classes Define abstract types and have the container automatically inject the implementation.
:factory: Factory pattern Defer instantiation to specialized factories for full control over object creation when necessary.
:one: Singleton/Transient dependencies Declare dependencies as transient or singletons which tells the container whether to inject a fresh copy or reuse existing instances.
:package: Declarative/Imperative Configure services through annotations in a fully declarative style or build everything by code for full control over instantiation.

Why wireup over existing packages:

  • ⁠Fully typed. Both wireup and your service objects.
  • ⁠No patching! Services/factories are not modified and can be easily tested in isolation from the container or their dependencies.
  • Simple but powerful syntax.
  • Straight to the point. No excessive ceremony or boilerplate.
  • ⁠Easy to introduce to existing projects.
  • ⁠It’s predictable: No use of *args, or **kwargs. Service declarations are just like regular classes/dataclasses and can be fully linted and type-checked.

Examples

from wireup import service


@service
@dataclass
class S3Manager:
    # Reference configuration by name.
    # This is the same name this appears in settings.
    access_token: Annotated[str, Inject(param="S3_BUCKET_ACCESS_TOKEN")]

    def upload(self, file: File) -> None: ...
from wireup import container


@container.autowire
def upload_file_view(request: HttpRequest, s3_manager: S3Manager) -> HttpResponse:
    return HttpResponse(...)

Looking forward to your thoughts.