asynctasq 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. asynctasq-1.0.0/PKG-INFO +607 -0
  2. asynctasq-1.0.0/README.md +555 -0
  3. asynctasq-1.0.0/pyproject.toml +200 -0
  4. asynctasq-1.0.0/src/asynctasq/__init__.py +323 -0
  5. asynctasq-1.0.0/src/asynctasq/__main__.py +218 -0
  6. asynctasq-1.0.0/src/asynctasq/cli/__init__.py +5 -0
  7. asynctasq-1.0.0/src/asynctasq/cli/commands/migrate.py +76 -0
  8. asynctasq-1.0.0/src/asynctasq/cli/commands/worker.py +43 -0
  9. asynctasq-1.0.0/src/asynctasq/cli/config.py +174 -0
  10. asynctasq-1.0.0/src/asynctasq/cli/main.py +54 -0
  11. asynctasq-1.0.0/src/asynctasq/cli/parser.py +279 -0
  12. asynctasq-1.0.0/src/asynctasq/cli/utils.py +49 -0
  13. asynctasq-1.0.0/src/asynctasq/config.py +260 -0
  14. asynctasq-1.0.0/src/asynctasq/core/dispatcher.py +216 -0
  15. asynctasq-1.0.0/src/asynctasq/core/driver_factory.py +153 -0
  16. asynctasq-1.0.0/src/asynctasq/core/models.py +66 -0
  17. asynctasq-1.0.0/src/asynctasq/core/worker.py +643 -0
  18. asynctasq-1.0.0/src/asynctasq/drivers/__init__.py +15 -0
  19. asynctasq-1.0.0/src/asynctasq/drivers/base_driver.py +385 -0
  20. asynctasq-1.0.0/src/asynctasq/drivers/mysql_driver.py +775 -0
  21. asynctasq-1.0.0/src/asynctasq/drivers/postgres_driver.py +667 -0
  22. asynctasq-1.0.0/src/asynctasq/drivers/rabbitmq_driver.py +928 -0
  23. asynctasq-1.0.0/src/asynctasq/drivers/redis_driver.py +623 -0
  24. asynctasq-1.0.0/src/asynctasq/drivers/retry_utils.py +40 -0
  25. asynctasq-1.0.0/src/asynctasq/drivers/sqs_driver.py +555 -0
  26. asynctasq-1.0.0/src/asynctasq/integrations/fastapi.py +203 -0
  27. asynctasq-1.0.0/src/asynctasq/monitoring/__init__.py +49 -0
  28. asynctasq-1.0.0/src/asynctasq/monitoring/emitters.py +267 -0
  29. asynctasq-1.0.0/src/asynctasq/monitoring/monitoring.py +254 -0
  30. asynctasq-1.0.0/src/asynctasq/monitoring/registry.py +61 -0
  31. asynctasq-1.0.0/src/asynctasq/monitoring/types.py +94 -0
  32. asynctasq-1.0.0/src/asynctasq/py.typed +0 -0
  33. asynctasq-1.0.0/src/asynctasq/serializers/__init__.py +66 -0
  34. asynctasq-1.0.0/src/asynctasq/serializers/base_serializer.py +60 -0
  35. asynctasq-1.0.0/src/asynctasq/serializers/hooks/__init__.py +82 -0
  36. asynctasq-1.0.0/src/asynctasq/serializers/hooks/base.py +426 -0
  37. asynctasq-1.0.0/src/asynctasq/serializers/hooks/builtin.py +93 -0
  38. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/__init__.py +65 -0
  39. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/base.py +127 -0
  40. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/django.py +76 -0
  41. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/lazy_proxy.py +218 -0
  42. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/lazy_proxy_hook.py +134 -0
  43. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/sqlalchemy.py +530 -0
  44. asynctasq-1.0.0/src/asynctasq/serializers/hooks/orm/tortoise.py +151 -0
  45. asynctasq-1.0.0/src/asynctasq/serializers/msgpack_serializer.py +143 -0
  46. asynctasq-1.0.0/src/asynctasq/tasks/__init__.py +29 -0
  47. asynctasq-1.0.0/src/asynctasq/tasks/core/__init__.py +10 -0
  48. asynctasq-1.0.0/src/asynctasq/tasks/core/base_task.py +324 -0
  49. asynctasq-1.0.0/src/asynctasq/tasks/core/task_config.py +77 -0
  50. asynctasq-1.0.0/src/asynctasq/tasks/infrastructure/__init__.py +7 -0
  51. asynctasq-1.0.0/src/asynctasq/tasks/infrastructure/process_pool_manager.py +590 -0
  52. asynctasq-1.0.0/src/asynctasq/tasks/services/__init__.py +11 -0
  53. asynctasq-1.0.0/src/asynctasq/tasks/services/executor.py +156 -0
  54. asynctasq-1.0.0/src/asynctasq/tasks/services/function_resolver.py +250 -0
  55. asynctasq-1.0.0/src/asynctasq/tasks/services/repository.py +125 -0
  56. asynctasq-1.0.0/src/asynctasq/tasks/services/serializer.py +218 -0
  57. asynctasq-1.0.0/src/asynctasq/tasks/services/task_info_converter.py +112 -0
  58. asynctasq-1.0.0/src/asynctasq/tasks/types/__init__.py +17 -0
  59. asynctasq-1.0.0/src/asynctasq/tasks/types/async_process_task.py +236 -0
  60. asynctasq-1.0.0/src/asynctasq/tasks/types/async_task.py +101 -0
  61. asynctasq-1.0.0/src/asynctasq/tasks/types/function_task.py +367 -0
  62. asynctasq-1.0.0/src/asynctasq/tasks/types/sync_process_task.py +130 -0
  63. asynctasq-1.0.0/src/asynctasq/tasks/types/sync_task.py +103 -0
  64. asynctasq-1.0.0/src/asynctasq/tasks/utils/__init__.py +17 -0
  65. asynctasq-1.0.0/src/asynctasq/tasks/utils/execution_helpers.py +125 -0
  66. asynctasq-1.0.0/src/asynctasq/tasks/utils/logger.py +56 -0
  67. asynctasq-1.0.0/src/asynctasq/tasks/utils/type_guards.py +44 -0
  68. asynctasq-1.0.0/src/asynctasq/utils/cleanup_hooks.py +221 -0
  69. asynctasq-1.0.0/src/asynctasq/utils/console.py +33 -0
  70. asynctasq-1.0.0/src/asynctasq/utils/loop.py +132 -0
@@ -0,0 +1,607 @@
1
+ Metadata-Version: 2.3
2
+ Name: asynctasq
3
+ Version: 1.0.0
4
+ Summary: AsyncTasQ: 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, smart ORM serialization (SQLAlchemy, Django, Tortoise) using msgpack reduces payloads by 90%+.
5
+ Keywords: queue,task,async,laravel,redis,sqs,background-tasks,worker,fastapi,sqlalchemy,django,tortoise-orm
6
+ Author: Adam Refaey
7
+ License: MIT
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Dist: msgpack>=1.1.0
17
+ Requires-Dist: rich>=14.2.0
18
+ Requires-Dist: asynctasq[uvloop,redis,sqs,postgres,mysql,rabbitmq,sqlalchemy,django,tortoise,fastapi,monitor] ; extra == 'all'
19
+ Requires-Dist: django>=5.2.8 ; extra == 'django'
20
+ Requires-Dist: psycopg2-binary>=2.9.11 ; extra == 'django'
21
+ Requires-Dist: fastapi>=0.115.0 ; extra == 'fastapi'
22
+ Requires-Dist: redis[hiredis]>=7.1.0 ; extra == 'monitor'
23
+ Requires-Dist: asyncmy>=0.2.10 ; extra == 'mysql'
24
+ Requires-Dist: cryptography>=46.0.0 ; extra == 'mysql'
25
+ Requires-Dist: asyncpg>=0.30.0 ; extra == 'postgres'
26
+ Requires-Dist: asyncpg-stubs>=0.30.0 ; extra == 'postgres'
27
+ Requires-Dist: aio-pika>=9.5.8 ; extra == 'rabbitmq'
28
+ Requires-Dist: redis[hiredis]>=7.1.0 ; extra == 'redis'
29
+ Requires-Dist: sqlalchemy>=2.0.44 ; extra == 'sqlalchemy'
30
+ Requires-Dist: greenlet>=3.2.4 ; extra == 'sqlalchemy'
31
+ Requires-Dist: aioboto3>=15.5.0 ; extra == 'sqs'
32
+ Requires-Dist: types-aioboto3[sqs]>=15.5.0 ; extra == 'sqs'
33
+ Requires-Dist: tortoise-orm>=0.25.1 ; extra == 'tortoise'
34
+ Requires-Dist: uvloop>=0.22.1 ; extra == 'uvloop'
35
+ Requires-Python: >=3.12
36
+ Project-URL: Homepage, https://github.com/adamrefaey/asynctasq
37
+ Project-URL: Issues, https://github.com/adamrefaey/asynctasq/issues
38
+ Project-URL: Repository, https://github.com/adamrefaey/asynctasq
39
+ Provides-Extra: all
40
+ Provides-Extra: django
41
+ Provides-Extra: fastapi
42
+ Provides-Extra: monitor
43
+ Provides-Extra: mysql
44
+ Provides-Extra: postgres
45
+ Provides-Extra: rabbitmq
46
+ Provides-Extra: redis
47
+ Provides-Extra: sqlalchemy
48
+ Provides-Extra: sqs
49
+ Provides-Extra: tortoise
50
+ Provides-Extra: uvloop
51
+ Description-Content-Type: text/markdown
52
+
53
+ # AsyncTasQ
54
+
55
+ [![Tests](https://raw.githubusercontent.com/adamrefaey/asynctasq/main/.github/tests.svg)](https://github.com/adamrefaey/asynctasq/actions/workflows/ci.yml)
56
+ [![Coverage](https://raw.githubusercontent.com/adamrefaey/asynctasq/main/.github/coverage.svg)](https://raw.githubusercontent.com/adamrefaey/asynctasq/main/.github/coverage.svg)
57
+ [![Python Version](https://raw.githubusercontent.com/adamrefaey/asynctasq/main/.github/python-version.svg)](https://www.python.org/downloads/)
58
+ [![PyPI Version](https://img.shields.io/pypi/v/asynctasq)](https://pypi.org/project/asynctasq/)
59
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
60
+
61
+ A modern, async-first, type-safe task queue for Python 3.12+. Inspired by Laravel's elegant queue system. 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, and real-time event streaming.
62
+
63
+ ---
64
+
65
+ ## Table of Contents
66
+
67
+ - [Quick Start](#quick-start)
68
+ - [Documentation](#documentation)
69
+ - [Examples](#examples)
70
+ - [Why AsyncTasQ?](#why-asynctasq)
71
+ - [Key Features](#key-features)
72
+ - [Comparison with Alternatives](#comparison-with-alternatives)
73
+ - [Contributing](#contributing)
74
+ - [License](#license)
75
+ - [Support](#support)
76
+ - [Roadmap](#roadmap)
77
+
78
+ ---
79
+
80
+ ## Quick Start
81
+
82
+ Get started in 60 seconds:
83
+
84
+ Install AsyncTasQ (Python 3.12+ required)
85
+
86
+ ```bash
87
+ uv add asynctasq[redis]
88
+ ```
89
+
90
+ Note: This example requires a Redis server running on localhost:6379. If you don't have Redis installed, you can start one using Docker:
91
+
92
+ ```bash
93
+ docker run -d --name redis-test -p 127.0.0.1:6379:6379 redis:8.0-alpine
94
+ ```
95
+
96
+ Create a new file named `quick_start.py` and add the following code:
97
+
98
+ ```python
99
+ import asyncio
100
+
101
+ from asynctasq import AsyncTask, RedisConfig, TaskConfig, init, print, task
102
+
103
+ # 1. Configure AsyncTasQ
104
+ init({"driver": "redis", "redis": RedisConfig(url="redis://localhost:6379")})
105
+
106
+
107
+ # 2. Define tasks (function-based or class-based)
108
+ # Function-based task
109
+ @task
110
+ async def send_email(to: str, subject: str, body: str):
111
+ # Use asynctasq.print() for beautiful Rich-formatted console output
112
+ print(f"[cyan]Sending email to[/cyan] [yellow]{to}[/yellow]: [bold]{subject}[/bold]")
113
+ await asyncio.sleep(1) # Simulate email sending
114
+ return f"Email sent to {to}"
115
+
116
+
117
+ # Class-based task with TaskConfig
118
+ class ProcessPayment(AsyncTask[bool]):
119
+ config: TaskConfig = {
120
+ "queue": "payments",
121
+ "max_attempts": 3,
122
+ "retry_delay": 60,
123
+ "timeout": 30,
124
+ "correlation_id": None,
125
+ }
126
+
127
+ def __init__(self, user_id: int, amount: float, **kwargs):
128
+ super().__init__(**kwargs)
129
+ self.user_id = user_id
130
+ self.amount = amount
131
+
132
+ async def execute(self) -> bool:
133
+ # Use asynctasq.print() for beautiful Rich-formatted console output
134
+ print(
135
+ f"[green]Processing[/green] [bold]${self.amount}[/bold] for user [cyan]{self.user_id}[/cyan]"
136
+ )
137
+ await asyncio.sleep(2) # Simulate payment processing
138
+ return True
139
+
140
+
141
+ # 3. Dispatch tasks with optional configuration chaining
142
+ async def main():
143
+ # Function-based task dispatch
144
+ for i in range(10):
145
+ task_id = await send_email(
146
+ to=f"user{i}@example.com", subject=f"Welcome {i}!", body="Welcome to our platform!"
147
+ ).dispatch()
148
+ print(f"Task dispatched: {task_id}")
149
+
150
+ # Class-based task dispatch with TaskConfig defaults
151
+ payment_task_id = await ProcessPayment(user_id=123, amount=99.99).dispatch()
152
+ print(f"Payment task dispatched: {payment_task_id}")
153
+
154
+ # With configuration chaining (overrides TaskConfig)
155
+ critical_task_id = (
156
+ await send_email(to="admin@example.com", subject="Critical Alert", body="System issue!")
157
+ .on_queue("high-priority")
158
+ .max_attempts(10)
159
+ .timeout(60)
160
+ .dispatch()
161
+ )
162
+ print(f"Critical task dispatched: {critical_task_id}")
163
+
164
+ # Class-based with method chaining
165
+ urgent_payment_id = (
166
+ await ProcessPayment(user_id=456, amount=199.99)
167
+ .on_queue("urgent")
168
+ .max_attempts(5)
169
+ .timeout(120)
170
+ .dispatch()
171
+ )
172
+ print(f"Urgent payment dispatched: {urgent_payment_id}")
173
+
174
+
175
+ if __name__ == "__main__":
176
+ # AsyncTasQ works with any event loop - choose what works best for you:
177
+
178
+ # Option 1: Use AsyncTasQ's runner (automatic uvloop support)
179
+ from asynctasq import run
180
+
181
+ run(main())
182
+
183
+ # Option 2: Use standard asyncio
184
+ # import asyncio
185
+ # asyncio.run(main())
186
+
187
+ # Option 3: Use uvloop directly
188
+ # import uvloop
189
+ # uvloop.run(main())
190
+
191
+ ```
192
+
193
+ Run the script to dispatch tasks:
194
+
195
+ ```bash
196
+ uv run python quick_start.py
197
+ ```
198
+
199
+ In a separate terminal, run the worker to process the tasks:
200
+
201
+ ```bash
202
+ uv run asynctasq worker --queues default,payments,high-priority,urgent
203
+ ```
204
+
205
+ **That's it!** Your first AsyncTasQ application is ready. AsyncTasQ works seamlessly with `asyncio.run()`, uvloop, FastAPI, Jupyter notebooks, or any other async framework - cleanup happens automatically when the event loop closes.
206
+
207
+ To stop and remove the Redis container when done:
208
+
209
+ ```bash
210
+ docker stop redis-test && docker rm redis-test
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Documentation
216
+
217
+ Comprehensive guides to get you started:
218
+
219
+ - **[Installation](https://github.com/adamrefaey/asynctasq/blob/main/docs/installation.md)** – Installation instructions for uv and pip
220
+ - **[Configuration](https://github.com/adamrefaey/asynctasq/blob/main/docs/configuration.md)** – Complete configuration guide with `asynctasq.init()` and `Config.get()`
221
+ - Configuration properties apply to different contexts: **dispatch** (when enqueuing tasks) vs **worker** (when processing tasks)
222
+ - Driver configs (redis, postgres, mysql, rabbitmq, sqs) and events config apply to **both contexts**
223
+ - Properties like `timeout` and `visibility_timeout` are configured **per-task** via TaskConfig
224
+ - **[Task Definitions](https://github.com/adamrefaey/asynctasq/blob/main/docs/task-definitions.md)** – Function-based and class-based tasks
225
+ - **[Queue Drivers](https://github.com/adamrefaey/asynctasq/blob/main/docs/queue-drivers.md)** – Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS
226
+ - **[Running Workers](https://github.com/adamrefaey/asynctasq/blob/main/docs/running-workers.md)** – CLI and programmatic workers
227
+ - **[Monitoring](https://github.com/adamrefaey/asynctasq/blob/main/docs/monitoring.md)** – Event streaming and queue statistics
228
+ - **[ORM Integrations](https://github.com/adamrefaey/asynctasq/blob/main/docs/orm-integrations.md)** – SQLAlchemy, Django, Tortoise ORM
229
+ - **[Framework Integrations](https://github.com/adamrefaey/asynctasq/blob/main/docs/framework-integrations.md)** – FastAPI integration
230
+ - **[CLI Reference](https://github.com/adamrefaey/asynctasq/blob/main/docs/cli-reference.md)** – Complete command reference
231
+ - **[Best Practices](https://github.com/adamrefaey/asynctasq/blob/main/docs/best-practices.md)** – Task design, queue organization, production deployment
232
+
233
+ ---
234
+
235
+ ## Examples
236
+
237
+ Complete code examples:
238
+
239
+ - **[Function-Based Tasks Examples](https://github.com/adamrefaey/asynctasq/blob/main/docs/examples/function-based-tasks.md)** – Decorators, configuration, and best practices
240
+ - **[Class-Based Tasks Examples](https://github.com/adamrefaey/asynctasq/blob/main/docs/examples/class-based-tasks.md)** – AsyncTask, SyncTask, ProcessTask variants
241
+
242
+ ---
243
+
244
+ ## Why AsyncTasQ?
245
+
246
+ ### True Async-First Architecture
247
+
248
+ Unlike Celery and RQ which are built on synchronous foundations, AsyncTasQ is **designed from the ground up for asyncio**:
249
+
250
+ - **Native async/await everywhere** – All core operations use asyncio, no threading or blocking on critical paths
251
+ - **Multiple execution modes** – Choose between async I/O (event loop), sync I/O (thread pool), or CPU-bound (process pool) for each task
252
+ - **High-performance concurrency** – Process hundreds of tasks concurrently with minimal overhead using asyncio's efficient task scheduling
253
+ - **Smart connection pooling** – All drivers use connection pools optimized for async operations
254
+ - **Non-blocking by design** – Worker polling, task execution, and all I/O operations are truly non-blocking
255
+ - **Universal event loop compatibility** – AsyncTasQ works seamlessly with any event loop (asyncio, uvloop, or custom implementations). Cleanup hooks automatically attach to running loops, so you can use `asyncio.run()`, uvloop, FastAPI, Jupyter notebooks, or any other async framework. The optional `asynctasq.utils.loop.run` helper provides uvloop support with automatic fallback to asyncio.
256
+
257
+ ### Intelligent Serialization & ORM Integration
258
+
259
+ - **msgpack binary encoding** – 2-3x faster than JSON with smaller payloads
260
+ - **Automatic ORM model handling** – Pass SQLAlchemy, Django ORM, or Tortoise ORM models directly as task arguments. AsyncTasQ automatically:
261
+ - Serializes them as lightweight references (primary key only)
262
+ - Reduces payload size by 90%+
263
+ - Re-fetches with fresh data when the task executes
264
+ - Supports all 3 major Python ORMs out of the box
265
+ - **Smart type handling** – Native support for `datetime`, `Decimal`, `UUID`, `set`, and custom types without manual conversion
266
+
267
+ ### Enterprise-Grade Reliability
268
+
269
+ - **ACID guarantees** – PostgreSQL and MySQL drivers provide transactional dequeue with exactly-once processing semantics
270
+ - **Built-in dead-letter queues** – PostgreSQL/MySQL drivers automatically move permanently failed tasks to DLQ for inspection
271
+ - **Crash recovery** – Visibility timeouts ensure no task is lost even if workers crash mid-execution
272
+ - **Graceful shutdown** – SIGTERM/SIGINT handlers drain in-flight tasks before stopping (configurable timeout)
273
+ - **Flexible retry strategies** – Per-task retry configuration with custom `should_retry()` hooks for intelligent retry logic
274
+ - **Task timeout protection** – Prevent runaway tasks with configurable per-task timeouts
275
+ - **Real-time observability** – Redis Pub/Sub event streaming broadcasts task lifecycle events for monitoring dashboards
276
+
277
+ ### Developer Experience That Just Works
278
+
279
+ - **Elegant, Laravel-inspired API** – Clean, intuitive syntax that feels natural
280
+ - **Full type safety** – Complete type hints, mypy/pyright compatible, Generic `Task[T]` for return type checking
281
+ - **Simple configuration** – Use `asynctasq.init()` and `Config.get()` for all configuration needs
282
+ - **Two task styles** – Choose function-based `@task` decorators or class-based tasks with lifecycle hooks
283
+ - **Fluent method chaining** – Configure tasks expressively: `.delay(60).on_queue("high").max_attempts(10).timeout(300).dispatch()`
284
+ - **Beautiful console output** – Built-in Rich integration provides colorized logging, syntax highlighting, and formatted output. Use `asynctasq.print()` in tasks for gorgeous terminal displays with zero configuration
285
+ - **First-class FastAPI integration** – Lifespan management, automatic connection pooling, native async support
286
+
287
+ ### Multi-Driver Flexibility Without Vendor Lock-In
288
+
289
+ - **5 production-ready drivers** – Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS – all with the same API
290
+ - **Switch with one line** – Change `driver="redis"` to `driver="postgres"` – no code changes needed
291
+ - **Per-task driver override** – Use Redis for high-throughput tasks, PostgreSQL for ACID-critical tasks in the same application
292
+ - **Same API, different guarantees** – Choose the driver that matches your SLA requirements without rewriting code
293
+
294
+ ---
295
+
296
+ ## Key Features
297
+
298
+ ### Core Capabilities
299
+
300
+ - ✅ **Async-first design** with asyncio throughout the stack
301
+
302
+ - ✅ **Multiple queue drivers**: Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS
303
+
304
+ - ✅ **High-performance msgpack serialization** with binary support
305
+
306
+ - ✅ **Automatic ORM model handling** for SQLAlchemy, Django, Tortoise
307
+
308
+ - ✅ **Type-safe** with full type hints and Generic support
309
+
310
+ - ✅ **Three execution modes**: Async (I/O), Thread pool (moderate CPU), Process pool (heavy CPU)
311
+
312
+ - ✅ **Beautiful console output** with Rich library integration for colorized logs and formatted task output
313
+
314
+ - ✅ **Configurable retries** with custom retry logic hooks
315
+
316
+ - ✅ **Task timeouts** to prevent runaway tasks
317
+
318
+ - ✅ **Delayed task execution** with precision timing
319
+
320
+ - ✅ **Queue priority** with multiple queues per worker
321
+
322
+ - ✅ **Graceful shutdown** with signal handlers
323
+
324
+ ### Enterprise Features
325
+
326
+ - ✅ **ACID guarantees** (PostgreSQL/MySQL drivers)
327
+
328
+ - ✅ **Dead-letter queues** for failed task inspection
329
+
330
+ - ✅ **Visibility timeouts** for crash recovery
331
+
332
+ - ✅ **Connection pooling** for optimal resource usage
333
+
334
+ - ✅ **Transactional dequeue** with `SELECT FOR UPDATE SKIP LOCKED`
335
+
336
+ - ✅ **Task metadata tracking** (attempts, timestamps, task IDs)
337
+
338
+ - ✅ **Concurrent processing** with configurable worker concurrency
339
+
340
+ - ✅ **Real-time event streaming** via Redis Pub/Sub
341
+
342
+ ### Integrations
343
+
344
+ - ✅ **FastAPI** – Automatic lifecycle management, dependency injection
345
+
346
+ - ✅ **SQLAlchemy** – Async and sync model serialization
347
+
348
+ - ✅ **Django ORM** – Native async support (Django 3.1+)
349
+
350
+ - ✅ **Tortoise ORM** – Full async ORM integration
351
+
352
+ - ✅ **[asynctasq-monitor](https://github.com/adamrefaey/asynctasq-monitor)** – Real-time monitoring dashboard (optional)
353
+
354
+ ### Developer Tools
355
+
356
+ - ✅ **Comprehensive CLI** – Worker management and database migrations
357
+
358
+ - ✅ **Function-based tasks** with `@task` decorator
359
+
360
+ - ✅ **Class-based tasks** with 4 execution modes:
361
+ - `AsyncTask` – Async I/O-bound (API calls, async DB queries)
362
+ - `SyncTask` – Sync I/O-bound via thread pool (`requests`, sync DB drivers)
363
+ - `AsyncProcessTask` – Async CPU-intensive via process pool
364
+ - `SyncProcessTask` – Sync CPU-intensive via process pool (bypasses GIL)
365
+
366
+ - ✅ **Lifecycle hooks** – `execute()`, `failed()`, `should_retry()` for complete control
367
+
368
+ - ✅ **Method chaining** for fluent task configuration
369
+
370
+ - ✅ **Flexible configuration** – Use `asynctasq.init()` / `Config.get()` for all settings
371
+
372
+ ---
373
+
374
+ ## Comparison with Alternatives
375
+
376
+ ### AsyncTasQ vs. Celery
377
+
378
+ | Feature | AsyncTasQ | Celery |
379
+ | ------------------------ | ------------------------------------------------- | --------------------------------------------------------- |
380
+ | **Async Support** | ✅ Async-first, built with asyncio | ❌ No asyncio support (promised for years, not delivered) |
381
+ | **Type Safety** | ✅ Full type hints, Generic[T] | ⚠️ Third-party stubs (celery-types) |
382
+ | **Multi-Driver** | ✅ 5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | ⚠️ 3 brokers (Redis/RabbitMQ/SQS) |
383
+ | **ORM Integration** | ✅ Auto-serialization (SQLAlchemy/Django/Tortoise) | ❌ Manual serialization required |
384
+ | **Serialization** | ✅ msgpack (fast, binary, efficient) | ⚠️ JSON default (pickle/YAML/msgpack available) |
385
+ | **FastAPI Integration** | ✅ First-class, lifespan management | ⚠️ Manual setup, workarounds needed |
386
+ | **Dead-Letter Queue** | ✅ Built-in (PostgreSQL/MySQL) | ⚠️ Manual setup (RabbitMQ DLX) |
387
+ | **ACID Guarantees** | ✅ PostgreSQL/MySQL drivers | ❌ Not available |
388
+ | **Global Rate Limiting** | ⚠️ Not yet implemented | ❌ Not available (per-worker only) |
389
+ | **Setup Complexity** | ✅ Simple with `asynctasq.init()` | ⚠️ Complex configuration |
390
+ | **Prefetch Multiplier** | ✅ Sensible default (1) | ⚠️ Dangerous default (4x), often causes performance issues |
391
+ | **Learning Curve** | ✅ Simple, intuitive API | ⚠️ Steep learning curve |
392
+
393
+ **When to use AsyncTasQ:**
394
+
395
+ - Modern async Python applications (FastAPI, aiohttp, async web frameworks)
396
+ - Need true asyncio support for I/O-bound tasks (API calls, database queries)
397
+ - Type-safe codebase with full IDE support
398
+ - Multiple driver flexibility (dev → production migration)
399
+ - Automatic ORM model handling (SQLAlchemy, Django, Tortoise)
400
+ - Enterprise ACID requirements (financial transactions, critical workflows)
401
+ - Simple, clean API without steep learning curve
402
+
403
+ **When to use Celery:**
404
+
405
+ - Mature ecosystem with many plugins and extensions
406
+ - Complex workflows (chains, chords, groups with callbacks)
407
+ - Large existing Celery codebase that's not worth migrating
408
+ - Synchronous applications where asyncio isn't needed
409
+ - Need for battle-tested, widely-adopted solution
410
+
411
+ ---
412
+
413
+ ### AsyncTasQ vs. Dramatiq
414
+
415
+ | Feature | AsyncTasQ | Dramatiq |
416
+ | ----------------------- | ------------------------------------------------- | --------------------------------------------------------- |
417
+ | **Async Support** | ✅ Async-first, native asyncio | ⚠️ Limited (via async-dramatiq extension, not first-class) |
418
+ | **Type Safety** | ✅ Full type hints, Generic[T] | ✅ Type hints (py.typed) |
419
+ | **Multi-Driver** | ✅ 5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | ⚠️ 2 brokers (Redis/RabbitMQ) |
420
+ | **ORM Integration** | ✅ Auto-serialization (SQLAlchemy/Django/Tortoise) | ❌ Manual serialization required |
421
+ | **Dead-Letter Queue** | ✅ Built-in (PostgreSQL/MySQL) | ✅ Built-in (all brokers) |
422
+ | **FastAPI Integration** | ✅ First-class, lifespan management | ⚠️ Manual setup needed |
423
+ | **Database Drivers** | ✅ PostgreSQL/MySQL with ACID | ❌ Not available |
424
+ | **Simplicity** | ✅ Clean, intuitive API | ✅ Simple, well-designed |
425
+
426
+ **When to use AsyncTasQ:**
427
+
428
+ - Async-first applications (FastAPI, aiohttp, modern Python stack)
429
+ - True asyncio support for I/O-bound tasks
430
+ - Database-backed queues with ACID guarantees
431
+ - Automatic ORM model serialization
432
+ - Type-safe codebase with IDE support
433
+
434
+ **When to use Dramatiq:**
435
+
436
+ - Synchronous applications
437
+ - Mature, battle-tested solution needed
438
+ - Complex middleware requirements
439
+ - Don't need async support
440
+
441
+ ---
442
+
443
+ ### AsyncTasQ vs. ARQ (Async Redis Queue)
444
+
445
+ | Feature | AsyncTasQ | ARQ |
446
+ | ------------------------ | ------------------------------------------------- | ------------------------------------- |
447
+ | **Async Support** | ✅ Async-first, native asyncio | ✅ Async-first, native asyncio |
448
+ | **Multi-Driver** | ✅ 5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | ❌ Redis only |
449
+ | **Type Safety** | ✅ Full type hints, Generic[T] | ✅ Type hints |
450
+ | **ORM Integration** | ✅ Auto-serialization (SQLAlchemy/Django/Tortoise) | ❌ Manual serialization |
451
+ | **Serialization** | ✅ msgpack (binary, efficient) | ⚠️ pickle (default, security concerns) |
452
+ | **Dead-Letter Queue** | ✅ Built-in (PostgreSQL/MySQL) | ❌ Not available |
453
+ | **ACID Guarantees** | ✅ PostgreSQL/MySQL drivers | ❌ Not available |
454
+ | **FastAPI Integration** | ✅ First-class, lifespan management | ⚠️ Manual setup |
455
+ | **Task Execution Model** | ✅ At-least-once with idempotency support | ⚠️ At-least-once ("pessimistic") |
456
+ | **Simplicity** | ✅ Clean, Laravel-inspired API | ✅ Lightweight, minimal |
457
+ | **Custom Serializers** | ✅ Configurable serializers | ✅ Configurable serializers |
458
+
459
+ **When to use AsyncTasQ:**
460
+
461
+ - Need multiple driver options (not locked into Redis)
462
+ - Database-backed queues with ACID guarantees
463
+ - Automatic ORM model handling
464
+ - Dead-letter queue support for failed task inspection
465
+ - FastAPI applications with first-class integration
466
+ - Enterprise reliability requirements
467
+
468
+ **When to use ARQ:**
469
+
470
+ - Simple Redis-only infrastructure
471
+ - Lightweight solution with minimal dependencies
472
+ - Cron job scheduling is a primary requirement
473
+ - Mature async task queue needed
474
+ - Custom serializers (e.g., msgpack) are acceptable to configure manually
475
+
476
+ ---
477
+
478
+ ### AsyncTasQ vs. RQ (Redis Queue)
479
+
480
+ | Feature | AsyncTasQ | RQ |
481
+ | --------------------- | ------------------------------------------------- | -------------------------------- |
482
+ | **Async Support** | ✅ Async-first, native asyncio | ❌ Sync only (no asyncio support) |
483
+ | **Multi-Driver** | ✅ 5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | ❌ Redis only |
484
+ | **Type Safety** | ✅ Full type hints, Generic[T] | ✅ Type hints added |
485
+ | **Retries** | ✅ Configurable with custom `should_retry()` | ✅ Configurable retries |
486
+ | **Dead-Letter Queue** | ✅ Built-in (PostgreSQL/MySQL) | ❌ Not available |
487
+ | **Database Drivers** | ✅ PostgreSQL/MySQL with ACID | ❌ Not available |
488
+ | **Simplicity** | ✅ Intuitive, clean API | ✅ Very simple |
489
+
490
+ **When to use AsyncTasQ:**
491
+
492
+ - Async applications (FastAPI, aiohttp)
493
+ - True asyncio support for efficient I/O
494
+ - Multiple driver options
495
+ - Enterprise features (DLQ, ACID)
496
+ - ORM integration
497
+
498
+ **When to use RQ:**
499
+
500
+ - Simple, synchronous use cases
501
+ - Synchronous applications
502
+ - Redis-only infrastructure
503
+ - Need mature, battle-tested solution
504
+
505
+ ---
506
+
507
+ ### AsyncTasQ vs. Huey
508
+
509
+ | Feature | AsyncTasQ | Huey |
510
+ | ----------------------- | ------------------------------------------------- | -------------------------------------------------- |
511
+ | **Async Support** | ✅ Async-first, native asyncio | ⚠️ Limited (async result awaiting only via helpers) |
512
+ | **Multi-Driver** | ✅ 5 drivers (Redis/PostgreSQL/MySQL/RabbitMQ/SQS) | ⚠️ Redis/SQLite/Filesystem/Memory |
513
+ | **Type Safety** | ✅ Full type hints, Generic[T] | ⚠️ Limited type hints |
514
+ | **ORM Integration** | ✅ Auto-serialization (SQLAlchemy/Django/Tortoise) | ❌ Manual serialization |
515
+ | **Enterprise Features** | ✅ ACID, DLQ, visibility timeout | ⚠️ Basic features |
516
+ | **Simplicity** | ✅ Clean, modern API | ✅ Simple, lightweight |
517
+ | **Cron Jobs** | ⚠️ Not yet implemented | ✅ Built-in periodic tasks |
518
+
519
+ **When to use AsyncTasQ:**
520
+
521
+ - Async-first applications requiring true asyncio
522
+ - Enterprise requirements (ACID, DLQ)
523
+ - Type-safe codebase with IDE support
524
+ - Automatic ORM integration
525
+ - Need for multiple driver options
526
+
527
+ **When to use Huey:**
528
+
529
+ - Lightweight use cases
530
+ - Simple periodic/cron tasks
531
+ - SQLite-backed queues for embedded apps
532
+ - Mature, stable solution needed
533
+
534
+ ---
535
+
536
+ ### Key Differentiators
537
+
538
+ **AsyncTasQ stands out with:**
539
+
540
+ 1. **True async-first architecture** – Built with asyncio from the ground up (unlike Celery, RQ, Huey)
541
+ 2. **Multiple execution modes** – Choose async I/O, sync I/O (thread pool), or CPU-bound (process pool) per task
542
+ 3. **Intelligent ORM handling** – Automatic model serialization for SQLAlchemy, Django ORM, and Tortoise ORM (90%+ smaller payloads)
543
+ 4. **msgpack serialization** – Binary format that's 2-3x faster than JSON with smaller payloads
544
+ 5. **Multi-driver flexibility** – 5 production-ready drivers (Redis, PostgreSQL, MySQL, RabbitMQ, AWS SQS) with identical API
545
+ 6. **Type safety everywhere** – Full type hints with Generic[T] support, mypy/pyright compatible
546
+ 7. **Enterprise ACID guarantees** – PostgreSQL/MySQL drivers with transactional dequeue for exactly-once processing
547
+ 8. **Built-in dead-letter queues** – PostgreSQL/MySQL drivers automatically handle permanently failed tasks
548
+ 9. **First-class FastAPI integration** – Lifespan management, automatic connection pooling, native async support
549
+ 10. **Real-time event streaming** – Redis Pub/Sub broadcasts task lifecycle events for monitoring
550
+ 11. **Optional monitoring UI** – Beautiful real-time dashboard via [asynctasq-monitor](https://github.com/adamrefaey/asynctasq-monitor)
551
+ 12. **Elegant, Laravel-inspired API** – Method chaining (`.delay(60).on_queue("high").dispatch()`) and intuitive task definitions
552
+ 13. **Simple configuration** – Use `asynctasq.init()` and `Config.get()` for all configuration needs
553
+
554
+ ---
555
+
556
+ ## CI & Contributing (short)
557
+
558
+ - **One-line setup:** `just init` — install deps and pre-commit hooks
559
+ - **Start services:** `just docker-up` — Redis, PostgreSQL, MySQL, RabbitMQ, LocalStack (SQS) for local integration tests
560
+ - **Run tests:** `just test` — use `just test-unit` / `just test-integration` to scope
561
+ - **Run with coverage:** `just test-cov` or `pytest --cov=src/asynctasq --cov-report=html`
562
+ - **Run the worker locally:** `python -m asynctasq worker`
563
+ - **Pre-commit hooks:** [`./setup-pre-commit.sh`](https://github.com/adamrefaey/asynctasq/blob/main/setup-pre-commit.sh) or `just setup-hooks`
564
+ - **Format / lint / typecheck:** `just format`, `just lint`, `just typecheck`
565
+ - **CI runs on PRs and pushes to `main`** and includes lint, type checks and tests across Python 3.12–3.14.
566
+ - **Pre-commit hooks** enforce formatting and static checks locally before commits (see [`./setup-pre-commit.sh`](https://github.com/adamrefaey/asynctasq/blob/main/setup-pre-commit.sh)).
567
+ - **Branch protection:** enable required status checks (CI success, lint, unit/integration jobs) for `main`.
568
+ - **Coverage badge:** the repository updates `.github/coverage.svg` automatically via `.github/workflows/coverage-badge.yml`.
569
+ - **Run full CI locally:** `just ci` (runs format/lint/typecheck/tests like the workflow).
570
+
571
+ ---
572
+
573
+ ## Contributing
574
+
575
+ Contributions are welcome! Please see [CONTRIBUTING.md](https://github.com/adamrefaey/asynctasq/blob/main/CONTRIBUTING.md) for guidelines.
576
+
577
+ ---
578
+
579
+ ## License
580
+
581
+ MIT License – see [LICENSE](https://github.com/adamrefaey/asynctasq/blob/main/LICENSE) file for details.
582
+
583
+ ---
584
+
585
+ ## Support
586
+
587
+ - **Repository:** [github.com/adamrefaey/asynctasq](https://github.com/adamrefaey/asynctasq)
588
+ - **Issues:** [github.com/adamrefaey/asynctasq/issues](https://github.com/adamrefaey/asynctasq/issues)
589
+ - **Discussions:** [github.com/adamrefaey/asynctasq/discussions](https://github.com/adamrefaey/asynctasq/discussions)
590
+
591
+ ---
592
+
593
+ ## Roadmap
594
+
595
+ - [ ] SQLite driver support
596
+ - [ ] Oracle driver support
597
+ - [ ] Task batching support
598
+ - [ ] Task chaining and workflows (chains, chords, groups)
599
+ - [ ] Rate limiting
600
+ - [ ] Task priority within queues
601
+ - [ ] Scheduled/cron tasks
602
+
603
+ ---
604
+
605
+ ## Credits
606
+
607
+ Built with ❤️ by [Adam Refaey](https://github.com/adamrefaey).