Skip to main content

Dishka integration for RQ.

Project description

RQ integration for Dishka

PyPI version Supported versions License

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 DishkaWorker for auto-injection.
    • @inject decorator for manual setup with standard RQ workers.

Installation

Install using pip

pip install dishka-rq

Or with uv

uv add dishka-rq

Usage

Method 1: Using DishkaWorker Subclass

  1. 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)
  1. Annotate Task Dependencies

Use FromDishka[...] to mark injected parameters:

from dishka import FromDishka

def hello_world(hello: FromDishka[str]):
    return f"{hello} world!"
  1. 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.

  1. Set Up Providers and Container

Same as Method 1.

  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!"
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dishka_rq-0.1.2.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dishka_rq-0.1.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

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

Hashes for dishka_rq-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a710ae38125e0e314a2ec9b6b30d30c8fd2b899944b9b02b40674c2fc3ca6611
MD5 8391c9e0421eab9a43b00961e855dad8
BLAKE2b-256 6af0828a77ba966b446a7313ec4cf0d86dbbfac4baed089fe50821f1bd3f5bee

See more details on using hashes here.

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

Hashes for dishka_rq-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a8ef1db1ecb6e54e6b046bfe8313c84240a043ab864a785ca861baf8cc40587c
MD5 c1555853a2fe47358040eb9f0a42b617
BLAKE2b-256 290ab19a92d82106e4987d7f75f4639168a148ba7f55a9ef7d90d8a5869e33f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page