{"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":"en","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,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}