Dishka integration for RQ.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dishka_rq-0.1.2.tar.gz.
File metadata
- Download URL: dishka_rq-0.1.2.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a710ae38125e0e314a2ec9b6b30d30c8fd2b899944b9b02b40674c2fc3ca6611
|
|
| MD5 |
8391c9e0421eab9a43b00961e855dad8
|
|
| BLAKE2b-256 |
6af0828a77ba966b446a7313ec4cf0d86dbbfac4baed089fe50821f1bd3f5bee
|
File details
Details for the file dishka_rq-0.1.2-py3-none-any.whl.
File metadata
- Download URL: dishka_rq-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8ef1db1ecb6e54e6b046bfe8313c84240a043ab864a785ca861baf8cc40587c
|
|
| MD5 |
c1555853a2fe47358040eb9f0a42b617
|
|
| BLAKE2b-256 |
290ab19a92d82106e4987d7f75f4639168a148ba7f55a9ef7d90d8a5869e33f5
|