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.8

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.8
File Size Uploaded Provenance Actions
dependency_injection_pattern-0.0.8.tar.gz 17.4 kB With provenance Details for dependency_injection_pattern-0.0.8.tar.gz

Built distribution (wheel)

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

Total release size: 39.0 kB

Release files / dependency_injection_pattern-0.0.8.tar.gz

Download URL dependency_injection_pattern-0.0.8.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8af949734651a0e256bc405f1aab95d3b68958ae1f738af0234945b4b315139f
BLAKE2b-256 checksum
How to use checksums
35381a69a6d5f35e510fdd928fa408eeff35726ae9e76d16025ce574e876d58d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

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

Download URL dependency_injection_pattern-0.0.8-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4462582ad9b1fccd81ad435cda3586fa8d826261ec41eecce5b158f262fc4dec
BLAKE2b-256 checksum
How to use checksums
9d53af7daca1bcc5e4114c6dfeb2db4147dc25f3a2caf236ef5778d010f295d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Security for dependency-injection-pattern 0.0.8

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dependency_injection_pattern-0.0.8.tar.gz

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 Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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