RQ integration for Dishka
This package provides integration of Dishka DI framework and RQ task queue manager.
Features
- Automatic Scope Management: Handles REQUEST and SESSION scopes per RQ job execution.
- Dependency Injection: Injects dependencies into task handlers via:
- Subclassed
DishkaWorkerfor auto-injection. @injectdecorator for manual setup with standard RQ workers.
- Subclassed
Installation
Install using pip
pip install dishka-rq
Or with uv
uv add dishka-rq
Usage
Method 1: Using DishkaWorker Subclass
- Set Up Providers and Container
Define your Dishka providers and container as usual:
from dishka import Provider, Scope, provide, make_container
class StrProvider(Provider):
@provide(scope=Scope.REQUEST)
def hello(self) -> str:
return "Hello"
provider = StrProvider()
container = make_container(provider)
- Annotate Task Dependencies
Use FromDishka[...] to mark injected parameters:
from dishka import FromDishka
def hello_world(hello: FromDishka[str]):
return f"{hello} world!"
- Run worker
Start an RQ worker with DishkaWorker:
from dishka_rq import DishkaWorker
from redis import Redis
conn = Redis()
queues = ["default"]
worker = DishkaWorker(container=container, queues=queues, connection=conn)
worker.work(with_scheduler=True)
python run_worker.py
Method 2: Using @inject Decorator
If you don't need autoinjection or do not want to use custom DishkaWorker subclass.
- Set Up Providers and Container
Same as Method 1.
- Decorate Task Functions
Use @inject and annotate dependencies:
from dishka_rq import inject, FromDishka
@inject
def hello_world(hello: FromDishka[str]):
return f"{hello} world!"
- Configure Standard RQ Worker
Attach Dishka to an RQ worker:
from dishka_rq import setup_dishka
from rq import Worker
from redis import Redis
worker = Worker(queues=["default"], connection=Redis())
setup_dishka(worker, container)
worker.work(with_scheduler=True)
Requirements:
- Python 3.10+
- Dishka >= 1.4.2
- RQ >= 2.0
Release files for dishka-rq 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dishka_rq-0.1.2.tar.gz | 29.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dishka_rq-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.7 kB
Release files / dishka_rq-0.1.2.tar.gz
| Download URL | dishka_rq-0.1.2.tar.gz |
|---|---|
| Size | 29.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a710ae38125e0e314a2ec9b6b30d30c8fd2b899944b9b02b40674c2fc3ca6611
|
|
BLAKE2b-256 checksum How to use checksums |
6af0828a77ba966b446a7313ec4cf0d86dbbfac4baed089fe50821f1bd3f5bee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.23
|
Release files / dishka_rq-0.1.2-py3-none-any.whl
| Download URL | dishka_rq-0.1.2-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8ef1db1ecb6e54e6b046bfe8313c84240a043ab864a785ca861baf8cc40587c
|
|
BLAKE2b-256 checksum How to use checksums |
290ab19a92d82106e4987d7f75f4639168a148ba7f55a9ef7d90d8a5869e33f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.23
|