Skip to main content

Test Coverage Stable Version Pre-release Version PyPI - Python Version PyPI Downloads

Dependency Injection Pattern (Python)

A typed dependency injection framework for Python — focused on clarity, structure, and maintainability.

🚀 Why this exists

As Python applications grow, managing dependencies becomes increasingly difficult:

  • Hidden dependencies make systems harder to understand
  • Tight coupling reduces flexibility
  • Testing requires complex setup and mocking
  • Structure becomes inconsistent across modules

Unlike many other ecosystems, Python lacks a widely adopted, structured approach to dependency injection.

👉 This project aims to introduce clear, typed dependency management to Python applications.

✨ Features

  • 🧩 Strongly typed dependency injection
  • 🧠 Explicit dependency definitions
  • 🔄 Clear separation of concerns
  • 🧪 Improved testability
  • 🏗 Support for structured application architecture
  • ⚡ Lightweight and Python-native design

📦 Use cases

This library is particularly useful when building:

  • Backend services
  • Data engineering workflows
  • ETL pipelines
  • Modular applications
  • Systems with complex dependency graphs

👉 Especially valuable in projects where maintainability and scalability matter.

🏗 Design philosophy

This project is built around a few key principles:

1. Explicit over implicit

Dependencies should be visible and well-defined — not hidden in implementation details.

2. Type-driven structure

Type hints are used as a foundation for defining and resolving dependencies.

3. Maintainability over convenience

The goal is not to reduce lines of code — but to make systems easier to evolve.

4. Minimal abstraction

The framework avoids unnecessary complexity and stays close to Python’s core concepts.

🔗 What this enables

By introducing structured dependency injection, you get:

  • Clear boundaries between components
  • Easier reasoning about system design
  • More predictable runtime behavior
  • Improved ability to refactor safely

👉 This is especially powerful in larger systems where complexity grows over time.

⚖️ Trade-offs

Focus ✅ Not a goal ❌
Structured architecture Magic-based auto-wiring
Type safety Implicit dependency resolution
Clarity and control Minimal configuration at all costs

👉 This library prioritizes explicit design over automation.

🧠 Inspiration

Inspired by dependency injection patterns from ecosystems such as:

  • C# / .NET (built-in DI container)
  • Java (Spring, Guice)

But intentionally adapted to fit Python’s dynamic nature without introducing heavy frameworks or unnecessary indirection.

🎯 When to use

Use this library if you:

  • Are building medium to large Python applications
  • Want clearer separation between components
  • Need better testability
  • Prefer structured architecture over ad-hoc patterns

🚫 When not to use

This library may be unnecessary if:

  • Your project is small or short-lived
  • Dependency complexity is minimal
  • Simplicity is more important than structure

Part of a broader focus on:

  • Clean architecture
  • Runtime abstractions
  • Developer tooling in Python

👉 https://github.com/apmadsen

🤝 Contributing

Feedback, ideas, and contributions are welcome!

Example:

from logging import Logger
from di import Container

def get_logger() -> Logger:
    return Logger("app")

class Service1:
    def get_value(self) -> str:
        return "Some value"

class Service2:
    def __init__(self, service1: Service1, log: Logger):
        self.service1 = service1
        self.log = log

    def get_value(self) -> str:
        self.log.debug("Someone requested value...")
        return f"Service1 returned: {self.service1.get_value()}"

class Application:
    def __init__(self, service2: Service2, log: Logger):
        self.service2 = service2
        log.info("Application starting")

    def get_value(self) -> str:
        return f"Service2 returned: {self.service2.get_value()}"


container = Container()
container.add_singleton(get_logger)
container.add_transient(Service1)
container.add_transient(Service2)
container.add_transient(Application)

provider = container.provider() # container is sealed beyond this point

app = provider.provide(Application)

value = app.get_value() # => "Service2 returned: Service1 returned: Some value"

Full documentation

Go to documentation

Metadata

Release files for dependency-injection-pattern 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dependency-injection-pattern 0.0.7
File Size Uploaded
dependency_injection_pattern-0.0.7.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dependency-injection-pattern 0.0.7
File Interpreter ABI Platform
dependency_injection_pattern-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 38.2 kB

Release files / dependency_injection_pattern-0.0.7.tar.gz

Download URL dependency_injection_pattern-0.0.7.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
462377eaf42d8b9e1f014f7a0787f8c9d8c8a3bb85800bccf5724a41dfedcd05
BLAKE2b-256 checksum
How to use checksums
4f75f9fd965712f46505244b1ba620141c129f7ff606cab9fb0dcb6cf14536b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release files / dependency_injection_pattern-0.0.7-py3-none-any.whl

Download URL dependency_injection_pattern-0.0.7-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b72e145bc9276bda0ca4285a4f8d23066933cc00c85bdca74da1828a6a96077
BLAKE2b-256 checksum
How to use checksums
2cb964ae8937e847c1c26adf9193fde5ae0b291c773e87ccf6686fbc216cdbb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release 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