Registry / web-framework / taskiq-dependencies

taskiq-dependencies

JSON →
library1.5.7pypypi✓ verified 21d ago

taskiq-dependencies is a Python library providing a FastAPI-like dependency injection system. It allows for defining dependencies as functions and automatically resolving them for other callables. As a core component of the Taskiq asynchronous task queue ecosystem, it is actively maintained with frequent updates, currently at version 1.5.7.

pip install taskiq-dependencies
INSTALL
IMPORT
SIG · TASKIQ-DEPENDENCIE
T
taskiq-dependencies
web-frameworkpythonv1.5.7
Install
1.5s avg
Import
227ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.7 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.240s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.214s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

Depends
from taskiq_dependencies import Depends
inject_dependencies
from taskiq_dependencies import inject_dependencies

This quickstart demonstrates how to define and use dependencies with `taskiq-dependencies`. It covers both synchronous and asynchronous dependencies, showing how to use `Depends` to declare requirements and `inject_dependencies` to manually resolve and call the target function.

from taskiq_dependencies import Depends, inject_dependencies # A simple dependency that returns a user ID def get_user_id() -> int: return 1 # A function that uses the dependency def greet_user(user_id: int = Depends(get_user_id)) -> str: return f"Hello, user {user_id}" # Manually inject dependencies and call the function result = inject_dependencies(greet_user) print(result) # Example with async dependency import asyncio async def get_async_value() -> str: await asyncio.sleep(0.01) return "Async Value" async def process_async_data(value: str = Depends(get_async_value)) -> str: return f"Processed: {value}" # For async functions, inject_dependencies also returns an awaitable async def main(): async_result = await inject_dependencies(process_async_data) print(async_result) if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
gotchaUnlike web frameworks such as FastAPI, `taskiq-dependencies` does not automatically inject dependencies. You must explicitly call `inject_dependencies(your_function)` to resolve and execute the function with its dependencies.
fix
Always wrap your dependent function call with `inject_dependencies()`.
affects: All versions
gotchaDependency lifecycle and scope are single-shot per `inject_dependencies` call. This library does not provide request-scoped, session-scoped, or singleton dependency management out-of-the-box like a full web framework might. Each call to `inject_dependencies` re-evaluates all dependencies.
fix
Be mindful of the performance implications if dependencies are expensive to compute. For specific lifecycle management within `taskiq` tasks, consider how `taskiq`'s own integration (e.g., `TaskiqDepends`) might layer on top.
affects: All versions
gotchaWhile `taskiq-dependencies.Depends` works directly, when using it within `taskiq` tasks, it's often more idiomatic and potentially safer to use `taskiq.TaskiqDepends` if available. `Taskiq` uses `taskiq-dependencies` under the hood and may provide additional integration points or overrides specific to the task execution environment.
fix
For `taskiq` tasks, prefer `from taskiq import TaskiqDepends as Depends` to ensure full compatibility with the task queue's features and lifecycle management.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'taskiq_dependencies'
The 'taskiq-dependencies' library is not installed in the current Python environment.
fix
pip install taskiq-dependencies
taskiq_dependencies.exceptions.DependencyError: Cannot resolve dependency for parameter 'your_parameter_name'
The dependency injector failed to find or provide a value for a required parameter, often because the dependency function was not correctly specified or a transitive dependency could not be resolved.
fix
Ensure that the `Depends()` argument correctly points to a defined dependency function and that all nested dependencies are properly specified and resolvable, including correct type hints.
TypeError: 'generator' object is not callable
The `Depends()` constructor was incorrectly called with the result of a dependency function (e.g., `get_db()`) instead of the dependency function itself (e.g., `get_db`).
fix
Pass the dependency function reference to `Depends()`, not its call result: `db=Depends(get_db)`.
AttributeError: type object 'DependencyInjector' has no attribute 'collector'
The `@collector` decorator was incorrectly applied to the `DependencyInjector` class itself instead of an instantiated object of `DependencyInjector`.
fix
First, create an instance of `DependencyInjector` (e.g., `injector = DependencyInjector()`), then use its `@collector` decorator (e.g., `@injector.collector`).
Upgrade
Version history
1.5.7latest on PyPI · released Feb 26, 2025
Audit
Dependencies
typing_extensionsoptionalRequired for Python versions older than 3.9 if type hints like `Annotated` are used, though the package itself declares >=3.9 support. For Python 3.9+, it's not strictly necessary unless specific newer `typing_extensions` features are needed.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
taskiq-dependencies — pip install taskiq-dependencies · libregistry