Registry / web-framework / kink
library0.9.0pypypi✓ verified 85d ago

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 kink
INSTALL
IMPORT
SIG · KINK
K
kink
web-frameworkpythonv0.9.0
Install
1.6s avg
Import
213ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.225s · 18.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.201s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Container
from kink import Container
inject
from kink import inject
di
from kink import di
`di` is the global Container instance, commonly used for convenience.

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

from kink import di, inject class MyService: def __init__(self, message_prefix: str): self.message_prefix = message_prefix def get_greeting(self, name: str) -> str: return f"{self.message_prefix}, {name}!" @inject def run_application(service: MyService): print(service.get_greeting("World")) # Configure the Dependency Injection container di[str] = "Hello" di[MyService] = MyService # Kink automatically resolves 'message_prefix' from di[str] # Run the application, Kink injects MyService run_application()
Debug
Known issues
breakingKink dropped support for Python 3.7 in version 0.8.0. If you are using Python 3.7, you must either upgrade your Python version to 3.8+ or pin `kink` to a version older than 0.8.0 (e.g., `kink<0.8.0`).
fix
Upgrade Python to 3.8 or higher. Alternatively, downgrade Kink: `pip install 'kink<0.8.0'`
affects: >=0.8.0
gotchaPrior to version 0.8.1, the `@inject` decorator might not have correctly resolved all arguments when used with keyword arguments (`kwargs`) in function signatures, leading to unexpected `TypeError`s.
fix
Upgrade Kink to version 0.8.1 or newer: `pip install --upgrade kink`.
affects: <0.8.1
gotchaIf using Kink with Pydantic objects and the caching mechanism, a bug existed in versions prior to 0.8.1 where injection with the cache wrapper could fail. This was fixed in 0.8.1.
fix
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.
affects: <0.8.1
gotchaEarly versions of Kink had limited or no official support for Python's `Protocol` types or `Optional` types in dependency resolution. While `Optional` support was improved in 0.7.0 and `Protocol` support in 0.8.0, older versions may behave inconsistently with these advanced type hints.
fix
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`.
affects: <0.8.0
Errors
Common errors & fixes
TypeError: 'NoneType' object is not callable
A dependency required by an injected function or class constructor was not registered in the `kink.di` container, leading to `None` being injected for that dependency, which then cannot be called or accessed.
fix
Register the missing dependency in the `kink.di` container before the injection occurs, e.g., `di[MyDependencyClass] = MyDependencyClass` or `di[str] = 'default value'`.
TypeError: __init__() missing 1 required positional argument: 'some_arg'
Kink relies on type hints to identify and inject dependencies. This error often indicates that a constructor or function argument meant for injection either lacks a type hint or the type hint refers to a type not registered in the `di` container.
fix
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`.
Exception: This version of Python is not supported.
You are attempting to run Kink version 0.8.0 or newer on Python 3.7, which is no longer supported.
fix
Upgrade your Python environment to version 3.8 or higher. For example, use pyenv to install a newer Python version.
Upgrade
Version history
0.9.0latest on PyPI · released Mar 19, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
kink — pip install kink · libregistry