taskiq-fastapi
FastAPI integration for taskiq
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-fastapiuv
uv add taskiq-fastapipoetry
poetry add taskiq-fastapiInstalling 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
Tags
More Networking packages
h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
psutilpsutil retrieves real-time information about…
permissive · top 1,000 on PyPI
pyOpenSSLpyOpenSSL wraps OpenSSL's SSL/TLS functionality…
permissive · top 1,000 on PyPI
uvloopuvloop is a drop-in replacement for Python's…
permissive · top 1,000 on PyPI
execnetexecnet lets you spawn and communicate with…
permissive · top 1,000 on PyPI
pyzmqPyZMQ provides Python bindings for ZeroMQ…
permissive · top 1,000 on PyPI
taskiqTaskiq is an asynchronous distributed task…
permissive · top 5,000 on PyPI
taskiq-dependenciesProvides FastAPI-style dependency injection for…
unclear · top 5,000 on PyPI
taskiq-redisAdds Redis-based message brokers and result…
permissive · top 5,000 on PyPI
taskiq-aio-pikaProvides a RabbitMQ broker implementation for…
permissive · top 15,000 on PyPI
fast-dependsFastDepends provides a standalone dependency…
permissive · top 5,000 on PyPI
fastapi-injectableEnables FastAPI's Depends() dependency…
permissive · top 15,000 on PyPI
fasta2aFastA2A converts an AI agent into an…
permissive · top 15,000 on PyPI
codewords-clientA Python client library for the Codewords API…
permissive · top 5,000 on PyPI
fastapi-utilitiesProvides reusable utilities for FastAPI…
permissive · top 15,000 on PyPI
fastapi-decoratorsConverts functions into FastAPI-compatible…
permissive · top 15,000 on PyPI