Alluka
raw JSON → 0.4.0 verified Fri May 01 auth: no python
A type-based dependency injection framework for Python 3.11+ (up to <3.15). Current version 0.4.0, released 2024-11-24. Uses type hints to resolve dependencies; supports both sync and async callbacks. Active development, breaking changes in minor versions before 1.0.
pip install alluka Common errors
error alluka.errors.MissingDependencyError: No type dependency or callback known for type 'int' ↓
cause The requested type dependency (int) was not registered with client.set_type_dependency.
fix
Register the dependency: client.set_type_dependency(int, value)
error TypeError: call() got unexpected keyword argument '...' ↓
cause You passed an argument that conflicts with the callback's parameter names when using client.call.
fix
Ensure you are not passing keyword arguments that are meant to be injected. Use positional or key=value for explicit args.
Warnings
breaking Dropped Python 3.9 and 3.10 in v0.4.0; Python 3.11+ required. ↓
fix Upgrade Python to 3.11+ or stay on v0.3.x.
gotcha Callbacks decorated with @inject must be called through client.call or client.call_async, not directly. ↓
fix Use client.call(my_function) instead of my_function().
deprecated AsyncOnlyError renamed to SyncOnlyError in v0.1.3; AsyncOnlyError kept as deprecated alias. ↓
fix Use SyncOnlyError from alluka.exceptions.
Imports
- Client wrong
from alluka.abc import Clientcorrectfrom alluka import Client - inject
from alluka import inject
Quickstart
from alluka import Client, inject
client = Client()
client.set_type_dependency(int, 42)
@inject
def foo(value: int) -> str:
return f"Value: {value}"
result = client.call(foo)
print(result) # Value: 42