skillfed

taskiq-fastapi

FastAPI integration for taskiq

taskiq-fastapi v0.5.0 225.3K downloads/30d#9,222 on PyPI
Permissive license MIT Active released

What it is and what it does

taskiq-fastapi bridges FastAPI's dependency injection system with taskiq's distributed task queue. It allows task functions to depend on FastAPI Request objects and access application state (like database pools or configuration) that would normally only be available in HTTP handlers. The library works by injecting a worker-wide Request object at task startup, letting you reuse the same dependency functions across both FastAPI endpoints and taskiq tasks.

The package is designed for scenarios where you want to share business logic between synchronous HTTP handlers and asynchronous background tasks without duplicating dependency resolution. It requires explicit use of TaskiqDepends (rather than FastAPI's Depends) in task signatures so the taskiq resolver knows to inject dependencies. The documentation warns that the injected Request is a synthetic object created at worker startup, not tied to any actual HTTP request, and requires careful handling of broker startup/shutdown to avoid infinite recursion.

Use it for:

  • Share a database connection pool or Redis client between FastAPI endpoints and background tasks using the same dependency function.
  • Inject application configuration or secrets into task functions without passing them as explicit parameters.
  • Reuse FastAPI middleware-like logic (authentication, logging, tracing) in distributed task workers.
  • Set up integration tests with InMemoryBroker by manually populating the dependency context for both FastAPI and taskiq.
  • Build microservices where FastAPI handles HTTP requests and taskiq handles async work, both accessing the same application state.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Integrates FastAPI request and dependency injection into taskiq distributed tasks, allowing task functions to depend on FastAPI Request objects and shared application state.

Yes, if you are already using both FastAPI and taskiq and want to share dependency injection logic between them. The low install friction, permissive license, and active maintenance make it a reasonable choice. Be aware it is classified as Alpha, so expect potential API changes. Verify that the synthetic Request object meets your dependency needs before committing to production use.

Install

taskiq-fastapi on PyPI

pip

pip install taskiq-fastapi

uv

uv add taskiq-fastapi

poetry

poetry add taskiq-fastapi

Installing taskiq-fastapi

Before you install

Low install friction with only two runtime dependencies (taskiq and fastapi). Active maintenance as of 2026-04-18. Classified as Alpha, so expect API surface changes.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.

Quickstart

pip install taskiq-fastapi

import taskiq_fastapi
from taskiq import ZeroMQBroker
from fastapi import FastAPI

broker = ZeroMQBroker()
app = FastAPI()
taskiq_fastapi.init(broker, "myapp:app")

Requires Python 3.10 or later. Requires a running taskiq broker (e.g., ZeroMQ, Redis) and FastAPI application instance.

Verify before relying

  • Whether the synthetic Request object created by init() is sufficient for all FastAPI dependency patterns in production workloads.
  • Performance characteristics when dependency context is large or frequently updated.
  • Compatibility with FastAPI versions beyond those tested during development.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — taskiq, fastapi
Maintenance actively maintained — 118 days since the last release
First released
Downloads 225,315/month — #9,222 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: taskiq_fastapi-0.5.0-py3-none-any.whl

Keywords: taskiq, tasks, distributed, async, fastapi

Development Status :: 3 - AlphaIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: System :: NetworkingTyping :: Typed

Tags

fastapi taskiq integrationfastapi dependency injection tasksdistributed tasks with fastapitaskiq fastapi request contextasync task queue fastapi
fastapi-integrationtask-queuedependency-injection

More Networking packages