{"id":4794,"library":"taskiq-dependencies","title":"taskiq-dependencies","description":"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.","status":"active","version":"1.5.7","language":"python","source_language":"en","source_url":"https://github.com/taskiq-python/taskiq-dependencies","tags":["dependency-injection","async","fastapi-like","taskiq"],"install":[{"cmd":"pip install taskiq-dependencies","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required 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.","package":"typing_extensions","optional":true}],"imports":[{"symbol":"Depends","correct":"from taskiq_dependencies import Depends"},{"symbol":"inject_dependencies","correct":"from taskiq_dependencies import inject_dependencies"}],"quickstart":{"code":"from taskiq_dependencies import Depends, inject_dependencies\n\n# A simple dependency that returns a user ID\ndef get_user_id() -> int:\n    return 1\n\n# A function that uses the dependency\ndef greet_user(user_id: int = Depends(get_user_id)) -> str:\n    return f\"Hello, user {user_id}\"\n\n# Manually inject dependencies and call the function\nresult = inject_dependencies(greet_user)\nprint(result)\n\n# Example with async dependency\nimport asyncio\n\nasync def get_async_value() -> str:\n    await asyncio.sleep(0.01)\n    return \"Async Value\"\n\nasync def process_async_data(value: str = Depends(get_async_value)) -> str:\n    return f\"Processed: {value}\"\n\n# For async functions, inject_dependencies also returns an awaitable\nasync def main():\n    async_result = await inject_dependencies(process_async_data)\n    print(async_result)\n\nif __name__ == '__main__':\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Always wrap your dependent function call with `inject_dependencies()`.","message":"Unlike 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Dependency 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For `taskiq` tasks, prefer `from taskiq import TaskiqDepends as Depends` to ensure full compatibility with the task queue's features and lifecycle management.","message":"While `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.5.7':54 'activ':46 'allow':20 'async':58 'asynchron':40 'automat':27 'callabl':32 'compon':36 'core':35 'current':51 'defin':22 'depend':3,6,16,23,56 'dependency-inject':55 'ecosystem':43 'fastapi':14,60 'fastapi-lik':13,59 'frequent':49 'function':25 'inject':17,57 'librari':10 'like':15,61 'maintain':47 'provid':11 'python':9 'queue':42 'resolv':28 'system':18 'task':41 'taskiq':2,5,39,62 'taskiq-depend':1,4 'updat':50 'version':53","created_at":"2026-04-12T14:07:53.371382+00:00","updated_at":"2026-04-16T22:41:33.903158+00:00","problems":[{"fix":"pip install taskiq-dependencies","cause":"The 'taskiq-dependencies' library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'taskiq_dependencies'"},{"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.","cause":"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.","error":"taskiq_dependencies.exceptions.DependencyError: Cannot resolve dependency for parameter 'your_parameter_name'"},{"fix":"Pass the dependency function reference to `Depends()`, not its call result: `db=Depends(get_db)`.","cause":"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`).","error":"TypeError: 'generator' object is not callable"},{"fix":"First, create an instance of `DependencyInjector` (e.g., `injector = DependencyInjector()`), then use its `@collector` decorator (e.g., `@injector.collector`).","cause":"The `@collector` decorator was incorrectly applied to the `DependencyInjector` class itself instead of an instantiated object of `DependencyInjector`.","error":"AttributeError: type object 'DependencyInjector' has no attribute 'collector'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.5.7","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/taskiq-dependencies/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}