Kink is a lightweight dependency injection (DI) library for Python, offering a straightforward way to manage and inject services and dependencies. It supports constructor, method, and property injection, leveraging Python's type hints for automatic resolution. The library is actively maintained, with new versions typically released every few months, ensuring compatibility with recent Python versions and addressing community feedback.
pip install kinkVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a service with a dependency (a string prefix) using Kink's global `di` container and the `@inject` decorator for automatic dependency resolution. The `MyService` class requires a `message_prefix` which Kink resolves from the `di[str]` registration. The `run_application` function then receives an instance of `MyService`.
Upgrade Python to 3.8 or higher. Alternatively, downgrade Kink: `pip install 'kink<0.8.0'`
Upgrade Kink to version 0.8.1 or newer: `pip install --upgrade kink`.
Upgrade Kink to version 0.8.1 or newer: `pip install --upgrade kink`. This ensures correct interaction between Kink's injection and Pydantic objects with caching.
Ensure you are on Kink version 0.8.0 or newer to fully leverage `Protocol` and robust `Optional` type injection. Upgrade: `pip install --upgrade kink`.
Register the missing dependency in the `kink.di` container before the injection occurs, e.g., `di[MyDependencyClass] = MyDependencyClass` or `di[str] = 'default value'`.
Add appropriate type hints to all arguments that Kink should resolve (e.g., `def __init__(self, my_dep: MyDependency):`) and ensure `MyDependency` is registered in `kink.di`.
Upgrade your Python environment to version 3.8 or higher. For example, use pyenv to install a newer Python version.
No dependency data recorded yet.