{"id":24684,"library":"taskiq-fastapi","title":"TaskIQ FastAPI Integration","description":"TaskIQ-FastAPI provides integration between FastAPI and TaskIQ, allowing you to run background tasks with access to FastAPI's context (e.g., dependency injection, request state). Current version is 0.5.0, compatible with Python >=3.10. Release cadence is irregular, driven by TaskIQ ecosystem updates.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/taskiq-python/taskiq-fastapi","tags":["taskiq","fastapi","background-tasks","async","integration"],"install":[{"cmd":"pip install taskiq-fastapi","lang":"bash","label":"Default install"}],"dependencies":[{"reason":"Core dependency; taskiq-fastapi is an integration layer on top of TaskIQ.","package":"taskiq","optional":false},{"reason":"Required to use the integration with FastAPI applications.","package":"fastapi","optional":false}],"imports":[{"wrong":"from taskiq_fastapi import InitFastAPI","symbol":"init","correct":"from taskiq_fastapi import init"},{"symbol":"initializator","correct":"from taskiq_fastapi import initializator"},{"symbol":"populate_dependency_context","correct":"from taskiq_fastapi import populate_dependency_context"}],"quickstart":{"code":"from fastapi import FastAPI\nfrom taskiq import TaskIQ\nfrom taskiq_fastapi import InitFastAPI, TaskiqFastAPI\n\napp = FastAPI()\n\n# Initialize TaskIQ broker (e.g., InMemoryBroker)\nfrom taskiq import InMemoryBroker\nbroker = InMemoryBroker()\n\n# Attach FastAPI integration\ntaskiq_app = TaskiqFastAPI(app, broker)\n\n# Register an initialization callback (optional, for context access)\n@taskiq_app.on_app_init\ndef on_startup():\n    InitFastAPI().init()\n\n@app.get(\"/\")\nasync def root():\n    return {\"message\": \"Hello World\"}\n\n# Task must be defined after broker is available\n@broker.task\ndef my_task(param: str):\n    print(f\"Processing {param}\")\n    return param","lang":"python","description":"Minimal setup integrating TaskIQ with FastAPI using InMemoryBroker. Note: In production, use a persistent broker like Redis or RabbitMQ."},"warnings":[{"fix":"Use `from taskiq_fastapi import InitFastAPI, TaskiqFastAPI` instead of `from taskiq_fastapi.broker import ...`.","message":"In version 0.5.0, the import path changed from `taskiq_fastapi.broker` to `taskiq_fastapi` directly. Old imports will break.","severity":"breaking","affected_versions":"0.5.0"},{"fix":"Ensure `InitFastAPI().init()` is called at startup (e.g., in a lifespan event or by decorating a function with `@taskiq_app.on_app_init`).","message":"The `InitFastAPI` must be called during the app lifecycle (usually in a startup event or via `on_app_init` decorator) to inject FastAPI dependencies into tasks. Not calling it results in `RuntimeError: No request context available` when accessing FastAPI dependencies.","severity":"gotcha","affected_versions":"all"},{"fix":"Define task functions after the `TaskiqFastAPI` instance is created, or ensure the broker is correctly wired before task definitions.","message":"Tasks defined before the broker is attached to `TaskiqFastAPI` may not have access to context. Define tasks after calling `taskiq_app = TaskiqFastAPI(app, broker)`.","severity":"gotcha","affected_versions":"all"},{"fix":"Remove `middleware` parameter from `TaskiqFastAPI` and add `ResultBackendMiddleware` to the app if needed.","message":"The `TaskiqFastAPI` class previously accepted a `middleware` argument; this is deprecated in favor of using `ResultBackendMiddleware` separately.","severity":"deprecated","affected_versions":">=0.4.0"}],"env_vars":null,"search_vec":"'0.5.0':33 '3.10':37 'access':20 'allow':13 'async':52 'background':17,50 'background-task':49 'cadenc':39 'compat':34 'context':24 'current':30 'depend':26 'driven':42 'e.g':25 'ecosystem':45 'fastapi':2,6,10,22,48 'inject':27 'integr':3,8,53 'irregular':41 'provid':7 'python':36 'releas':38 'request':28 'run':16 'state':29 'task':18,51 'taskiq':1,5,12,44,47 'taskiq-fastapi':4 'updat':46 'version':31","created_at":"2026-05-01T08:14:23.410164+00:00","updated_at":"2026-05-01T08:14:23.410164+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/taskiq-fastapi/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","workflow","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}