Async Task Q

A modern, async-first, type-safe task queue Python package inspired by Laravel. Native FastAPI integration. Switch between multiple queue backends (Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS) with one config line. Automatic ORM serialization (SQLAlchemy, Django, Tortoise) using msgpack reduces payloads by 90%+. Features ACID guarantees, dead-letter queues, crash recovery.
Table of Contents
Why Async Task Q?
Async-First Architecture
- Built with asyncio from the ground up β No threading, no blocking operations on critical paths
- Native async/await support β Seamless integration with modern Python async code
- High concurrency β Process thousands of tasks concurrently with minimal resource usage
- Efficient I/O β Connection pooling for all database drivers
High-Performance Serialization
- msgpack encoding β Binary serialization that's faster and more compact than JSON
- Efficient binary handling β Native
use_bin_type=True for optimal bytes processing
- Automatic ORM model handling β Pass SQLAlchemy, Django, or Tortoise models directly as task parameters. They're automatically serialized as lightweight references (PK only), reducing payload size by 90%+, then re-fetched with fresh data when the task executes
- Custom type support β Native handling of datetime, Decimal, UUID, sets without manual conversion
Production-Ready Features
- Enterprise ACID guarantees β PostgreSQL/MySQL drivers with transactional dequeue
- Dead-letter queues β Automatic handling of permanently failed tasks
- Crash recovery β Visibility timeouts ensure tasks are never lost
- Graceful shutdown β SIGTERM/SIGINT handlers wait for in-flight tasks to complete
- Configurable retries β Per-task retry logic with custom
should_retry() hooks
- Task timeouts β Prevent runaway tasks with per-task timeout configuration
Developer Experience
- Elegant, intuitive API β Clean, expressive syntax inspired by Laravel's queue system
- Type-safe β Full type hints with mypy/pyright support, Generic Task[T] for return types
- Zero configuration β Works with environment variables out of the box
- Multiple task styles β Function-based decorators or class-based tasks with lifecycle hooks
- Method chaining β Fluent API for task configuration:
.delay(60).on_queue("high").dispatch()
- First-class FastAPI integration β Automatic lifecycle management and dependency injection
Multi-Driver Flexibility
- Switch drivers instantly β Change one config line to swap between Redis, PostgreSQL, MySQL, RabbitMQ, or AWS SQS
- Same API everywhere β Write once, run on any driver without code changes
- Per-task driver override β Different tasks can use different drivers in the same application
- Production-ready options β From Redis to enterprise databases to managed cloud queues
Key Features
Core Capabilities
-
β
Async-first design with asyncio throughout the stack
-
β
Multiple queue drivers: Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS
-
β
High-performance msgpack serialization with binary support
-
β
Automatic ORM model handling for SQLAlchemy, Django, Tortoise
-
β
Type-safe with full type hints and Generic support
-
β
Configurable retries with custom retry logic hooks
-
β
Task timeouts to prevent runaway tasks
-
β
Delayed task execution with precision timing
-
β
Queue priority with multiple queues per worker
-
β
Graceful shutdown with signal handlers
Enterprise Features
-
β
ACID guarantees (PostgreSQL/MySQL drivers)
-
β
Dead-letter queues for failed task inspection
-
β
Visibility timeouts for crash recovery
-
β
Connection pooling for optimal resource usage
-
β
Transactional dequeue with SELECT FOR UPDATE SKIP LOCKED
-
β
Task metadata tracking (attempts, timestamps, task IDs)
-
β
Concurrent processing with configurable worker concurrency
Integrations
-
β
FastAPI β Automatic lifecycle management, dependency injection
-
β
SQLAlchemy β Async and sync model serialization
-
β
Django ORM β Native async support (Django 3.1+)
-
β
Tortoise ORM β Full async ORM integration
Developer Tools
-
β
Comprehensive CLI β Worker management and database migrations
-
β
Function-based tasks with @task decorator
-
β
Class-based tasks with lifecycle hooks (handle, failed, should_retry)
-
β
Method chaining for fluent task configuration
-
β
Environment variable configuration for 12-factor apps
Quick Start
Get started in 60 seconds:
uv add async-task-q[redis]
import asyncio
from async_task_q.config import set_global_config
from async_task_q.core.task import task
set_global_config(driver="redis", redis_url="redis://localhost:6379", redis_password=None)
@task
async def send_email(to: str, subject: str, body: str):
print(f"Sending email to {to}: {subject}")
await asyncio.sleep(1)
return f"Email sent to {to}"
async def main():
for i in range(10):
task_id = await send_email.dispatch(
to=f"user{i}@example.com", subject=f"Welcome {i}!", body="Welcome to our platform!"
)
print(f"Task dispatched: {task_id}")
if __name__ == "__main__":
asyncio.run(main())
python -m async_task_q worker
That's it! Your first async task queue is ready. Now let's explore the powerful features.
Quick Reference
- One-line setup:
just init β install deps and pre-commit hooks
- Start services:
just services-up β Redis, PostgreSQL, MySQL, RabbitMQ, LocalStack (SQS) for local integration tests
- Run tests:
just test (or pytest) β use just test-unit / just test-integration to scope
- Run with coverage:
just test-cov or pytest --cov=src/async_task_q --cov-report=html
- Run the worker locally:
python -m async_task_q worker
- Pre-commit hooks:
./setup-pre-commit.sh or just setup-hooks
- Format / lint / typecheck:
just format, just lint, just typecheck
CI & Contributing (short)
- CI runs on PRs and pushes to
main and includes lint, type checks and tests across Python 3.11β3.14.
- Pre-commit hooks enforce formatting and static checks locally before commits (see
./setup-pre-commit.sh).
- Branch protection: enable required status checks (CI success, lint, unit/integration jobs) for
main.
- Coverage badge: the repository updates
.github/coverage.svg automatically via .github/workflows/coverage-badge.yml.
- Run full CI locally:
just ci (runs format/lint/typecheck/tests like the workflow).
Comparison with Alternatives
Async Task Q vs. Celery
| Async Support | β
Async-first, built with asyncio | β No native asyncio support |
| Type Safety | β
Full type hints, Generic[T] | β οΈ Third-party stubs (celery-types) |
| Multi-Driver | β
5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | β οΈ Redis/RabbitMQ/SQS brokers |
| ORM Integration | β
Auto-serialization (SQLAlchemy/Django/Tortoise) | β Manual serialization |
| Serialization | β
msgpack (fast, binary) | β οΈ JSON/pickle (slower) |
| FastAPI Integration | β
First-class, lifespan management | β οΈ Manual setup |
| Dead-Letter Queue | β
Built-in (PG/MySQL) | β οΈ Manual setup (RabbitMQ DLX) |
| ACID Guarantees | β
PostgreSQL/MySQL drivers | β Not available |
| Setup Complexity | β
Zero-config with env vars | β οΈ Complex configuration |
| Learning Curve | β
Simple, intuitive API | β οΈ Steep learning curve |
When to use Async Task Q:
- Modern async Python applications
- Need for type safety and IDE support
- Multiple driver options (dev β production)
- Automatic ORM model handling
- FastAPI applications
- Enterprise ACID requirements
When to use Celery:
- Mature ecosystem with many plugins
- Need for complex workflows (chains, chords)
- Large existing Celery codebase
Async Task Q vs. Dramatiq
| Async Support | β
Async-first | β οΈ Limited (via middleware) |
| Type Safety | β
Full type hints | β
Type hints (py.typed) |
| Multi-Driver | β
5 drivers | β οΈ Redis/RabbitMQ |
| ORM Integration | β
Auto-serialization | β Manual serialization |
| Dead-Letter Queue | β
Built-in | β
Built-in |
| FastAPI Integration | β
First-class | β οΈ Manual setup |
| Database Drivers | β
PostgreSQL/MySQL | β Not available |
| Simplicity | β
Clean, intuitive API | β
Simple, well-designed |
When to use Async Task Q:
- Async applications (FastAPI, aiohttp)
- Type-safe codebase
- Database-backed queues (ACID)
- ORM model handling
When to use Dramatiq:
- Synchronous applications
- Need for mature, battle-tested library
- Complex middleware requirements
Async Task Q vs. RQ (Redis Queue)
| Async Support | β
Async-first | β Sync only |
| Multi-Driver | β
5 drivers | β Redis only |
| Type Safety | β
Full type hints | β
Type hints added |
| Retries | β
Configurable with custom logic | β
Configurable retries |
| Dead-Letter Queue | β
Built-in | β Not available |
| Database Drivers | β
PostgreSQL/MySQL | β Not available |
| Simplicity | β
Intuitive, clean API | β
Very simple |
When to use Async Task Q:
- Async applications
- Multiple driver options
- Enterprise features (DLQ, ACID)
- Type safety
When to use RQ:
- Simple use cases
- Synchronous applications
- Redis-only infrastructure
Async Task Q vs. Huey
| Async Support | β
Async-first | β οΈ Limited async |
| Multi-Driver | β
5 drivers | β οΈ Redis/SQLite |
| Type Safety | β
Full type hints | β Limited |
| ORM Integration | β
Auto-serialization | β Manual |
| Enterprise Features | β
ACID, DLQ, visibility timeout | β οΈ Basic features |
| Simplicity | β
Clean, modern API | β
Simple |
When to use Async Task Q:
- Async-first applications
- Enterprise requirements
- Type-safe codebase
- ORM integration
When to use Huey:
- Lightweight use cases
- Simple task queues
- SQLite-backed queues
Key Differentiators
Async Task Q stands out with:
- True async-first design β Built with asyncio from the ground up
- msgpack serialization β Faster and more efficient than JSON
- Intelligent ORM handling β Automatic model serialization for 3 major ORMs
- Multi-driver flexibility β Seamlessly switch between 5 production-ready drivers (Redis, PostgreSQL, MySQL, RabbitMQ, SQS)
- Type safety β Full type hints with Generic[T] support
- Enterprise ACID guarantees β PostgreSQL/MySQL drivers with transactional dequeue
- Dead-letter queues β Built-in support for failed task inspection
- FastAPI integration β First-class support with lifecycle management
- Elegant, expressive API β Method chaining and intuitive task definitions
- Zero configuration β Works with environment variables out of the box
Documentation
For detailed documentation, see the following guides:
- Installation β Installation instructions for uv and pip
- Queue Drivers β Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS
- ORM Integrations β SQLAlchemy, Django, Tortoise ORM
- Framework Integrations β FastAPI integration
- Task Definitions β Function-based and class-based tasks
- Running Workers β CLI and programmatic workers
- Configuration β Environment variables, programmatic, CLI
- CLI Reference β Complete command reference
- Best Practices β Task design, queue organization, production deployment
Examples
For complete examples, see the following guides:
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT License β see LICENSE file for details.
Support
Roadmap
Credits
Built with β€οΈ by Adam Refaey.