
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
duckdi
Advanced tools
DuckDI is a minimal, type-safe, and architecture-friendly dependency injection library for Python.
It provides a clean interface to register and resolve dependencies at runtime using a TOML-based configuration, following the duck typing principle: "if it implements the expected methods, itβs good enough."
Ideal for developers who want clarity, zero magic, and full control over dependency resolution.
ABC and regular classes (no need for Protocols)INJECTIONS_PATH)With Poetry:
poetry add duckdi
Or using pip:
pip install duckdi
from duckdi import Interface
from abc import ABC, abstractmethod
@Interface
class IUserRepository(ABC):
@abstractmethod
def get_user(self, user_id: str) -> dict: ...
from duckdi import register
class PostgresUserRepository(IUserRepository):
def get_user(self, user_id: str) -> dict:
return {"id": user_id, "name": "John Doe"}
register(PostgresUserRepository)
You can also register it as a singleton:
register(PostgresUserRepository, is_singleton=True)
Create a file called injections.toml:
[injections]
"i_user_repository" = "postgres_user_repository"
Set the injection file path using the INJECTIONS_PATH environment variable:
export INJECTIONS_PATH=./injections.toml
from duckdi import Get
repo = Get(IUserRepository)
user = repo.get_user("123")
print(user) # {'id': '123', 'name': 'John Doe'}
MissingInjectionPayloadErrorRaised when no injection payload file is found at the specified path.
InvalidAdapterImplementationErrorRaised when the adapter registered does not implement the expected interface.
InterfaceAlreadyRegisteredErrorRaised when trying to register the same interface twice.
AdapterAlreadyRegisteredErrorRaised when the same adapter is registered more than once.
duckdi/
βββ pyproject.toml
βββ README.md
βββ src/
β βββ duckdi/
β βββ __init__.py
β βββ cli.py
β βββ duck.py
β βββ errors/
β β βββ __init__.py
β β βββ invalid_adapter_implementation_error.py
β β βββ interface_already_registered_error.py
β β βββ adapter_already_registered_error.py
β β βββ missing_injection_payload_error.py
β βββ utils/
β β βββ __init__.py
β β βββ buffer_readers.py
β β βββ to_snake.py
β βββ injections/
β βββ injections_container.py
β βββ injections_payload.py
βββ tests/
βββ test_interface.py
βββ test_register.py
βββ test_get.py
You can register multiple adapters and resolve them dynamically based on the TOML mapping:
from duckdi import Interface, register, Get
@Interface
class INotifier:
def send(self, msg: str): ...
class EmailNotifier(INotifier):
def send(self, msg: str):
print(f"Sending email: {msg}")
register(EmailNotifier)
# injections.toml
# [injections]
# "i_notifier" = "email_notifier"
notifier = Get(INotifier)
notifier.send("Hello from DuckDI!")
To run tests:
pytest
Or via Makefile:
make test
To check static typing:
make check
Licensed under the MIT License.
See the LICENSE file for more information.
Made with β€οΈ by PhePato
Pull requests, issues and ideas are always welcome!
FAQs
π¦ A minimal dependency injection library for Python
We found that duckdi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.