Taskiq is an asynchronous distributed task queue for Python, inspired by projects like Celery and Dramatiq. It supports both synchronous and asynchronous functions and integrates with popular async frameworks like FastAPI and AioHTTP. Taskiq is actively maintained with frequent releases, currently at version 0.12.1.
pip install taskiqVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define and execute an asynchronous task using Taskiq's `InMemoryBroker`. It covers defining a broker, decorating a function as a task, sending the task using `.kiq()`, and retrieving its result with `.wait_result()`. For distributed usage, an external worker process would be started to consume tasks from a real broker (like Redis or RabbitMQ).
Upgrade Python to 3.10 or higher. If unable to upgrade, pin Taskiq to `<0.12.0` in your `requirements.txt`.
For production, use a dedicated broker like `taskiq-redis`, `taskiq-aio-pika`, or `taskiq-nats`, which require separate installation and an external message queue service.
Always include `await broker.startup()` at the beginning and `await broker.shutdown()` at the end of your client-side application's lifecycle, typically within `asyncio.run()` or your main application entry point.
Upgrade to Taskiq `0.12.1` or newer, where this issue has been resolved. If upgrading is not immediately possible, avoid using `dataclasses` with tasks monitored by `TaskiqAdminMiddleware` on `0.12.0`.
Specify a more unique `--tasks-pattern` (e.g., `my_tasks.py`) or explicitly list task modules: `taskiq worker your_app.broker:broker your_app.tasks.module_a your_app.tasks.module_b`.
If using `ZeroMQBroker`, ensure you run only a single worker instance (e.g., `taskiq worker your_app:broker -w 1`). For multi-worker setups, choose a different broker like Redis or RabbitMQ.
pip install "taskiq[redis]"
Ensure your worker file (e.g., your_worker_file.py) contains a TaskiqApp instance named 'app', or specify the correct name and module path when running the worker: `taskiq worker your_worker_file:my_app_instance`
Convert the object to a serializable format (e.g., `datetime_obj.isoformat()`) before passing it to the task, or configure a custom serializer with appropriate encoders/decoders for these types.
Instantiate a broker (e.g., `InMemoryBroker`, `RedisBroker`) and pass it to the TaskiqApp constructor: `from taskiq import TaskiqApp, InMemoryBroker app = TaskiqApp(broker=InMemoryBroker())`
Replace calls like `app.add_task(my_func)` with decorating the function directly: `@app.task
def my_func():
pass`