Install & Compatibility
Where this runs
tested against v7.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Injector
✓ from dependencies import Injector
✗ from dependencies import Inject
Basic dependency injection setup: bind implementations and get instances.
from dependencies import Inject, This, value
class Logger:
pass
class Database:
def __init__(self, logger: Logger = This()):
self.logger = logger
def configure(binder):
db = Database()
binder.bind(Database, value(db))
binder.bind(Logger, value(Logger()))
container = Inject(autoload=False)
container.configure(configure)
db = container.instance(Database)
print(db.logger.__class__.__name__) # Logger
Debug
Known issues
gotchaInject must be used as a class instance, not a decorator. Common mistake: decorating with @Inject instead of instantiating and calling configure.fixUse `container = Inject(); container.configure(...)` instead of `@Inject`.
affects: >=7.0.0
breakingIn version 6.x, `Inject` was a decorator. In 7.x, it became a class. Import paths changed.fixUse `from dependencies import Inject` (class). Code using `@inject` must be rewritten.
affects: 7.0.0 to present
deprecatedUsing `This()` with non-type-hinted arguments may be deprecated in future versions.fixAlways provide type hints for parameters using `This()`.
affects: >=7.0.0
gotchaWhen using `autoload=False`, you must explicitly configure all dependencies. Common mistake: forgetting to bind a dependency leads to `DependencyError`.fixBind all dependencies with `binder.bind(...)` inside `configure` function.
affects: >=7.0.0
gotchaCircular dependencies are not detected automatically and cause recursion errors.fixAvoid circular references or use lazy injection with `This(lazy=True)`.
affects: >=7.0.0
Upgrade
Version history
7.7.1latest on PyPI · released Nov 24, 2024
Audit
Dependencies
No dependency data recorded yet.