Python implementation of the Dependency Injection pattern.
Project description
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
🔗 Related projects
Part of a broader focus on:
- Clean architecture
- Runtime abstractions
- Developer tooling in Python
🤝 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dependency_injection_pattern-0.0.7.tar.gz.
File metadata
- Download URL: dependency_injection_pattern-0.0.7.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462377eaf42d8b9e1f014f7a0787f8c9d8c8a3bb85800bccf5724a41dfedcd05
|
|
| MD5 |
b98e9faaee331cb43eba99f677b7b01a
|
|
| BLAKE2b-256 |
4f75f9fd965712f46505244b1ba620141c129f7ff606cab9fb0dcb6cf14536b4
|
Provenance
The following attestation bundles were made for dependency_injection_pattern-0.0.7.tar.gz:
Publisher:
python-publish.yml on apmadsen/dependency-injection-pattern
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dependency_injection_pattern-0.0.7.tar.gz -
Subject digest:
462377eaf42d8b9e1f014f7a0787f8c9d8c8a3bb85800bccf5724a41dfedcd05 - Sigstore transparency entry: 1731296793
- Sigstore integration time:
-
Permalink:
apmadsen/dependency-injection-pattern@a9d67cdf5c2efa4c15b85313dfe49d41805827b5 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a9d67cdf5c2efa4c15b85313dfe49d41805827b5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dependency_injection_pattern-0.0.7-py3-none-any.whl.
File metadata
- Download URL: dependency_injection_pattern-0.0.7-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b72e145bc9276bda0ca4285a4f8d23066933cc00c85bdca74da1828a6a96077
|
|
| MD5 |
6c17b27b16c457d7221eec380ad0884c
|
|
| BLAKE2b-256 |
2cb964ae8937e847c1c26adf9193fde5ae0b291c773e87ccf6686fbc216cdbb1
|
Provenance
The following attestation bundles were made for dependency_injection_pattern-0.0.7-py3-none-any.whl:
Publisher:
python-publish.yml on apmadsen/dependency-injection-pattern
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dependency_injection_pattern-0.0.7-py3-none-any.whl -
Subject digest:
8b72e145bc9276bda0ca4285a4f8d23066933cc00c85bdca74da1828a6a96077 - Sigstore transparency entry: 1731296809
- Sigstore integration time:
-
Permalink:
apmadsen/dependency-injection-pattern@a9d67cdf5c2efa4c15b85313dfe49d41805827b5 -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/apmadsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a9d67cdf5c2efa4c15b85313dfe49d41805827b5 -
Trigger Event:
release
-
Statement type: