Skip to main content

Apscheduler integration for dishka

Project description

APScheduler integration for Dishka

PyPI version Supported versions Downloads License GitHub Actions Workflow Status

This package provides integration of Dishka dependency injection framework and APScheduler, an advanced Python scheduler.

Installation

pip install apscheduler-dishka

Features

  • automatic REQUEST scope management for scheduled jobs
  • automatic injection of dependencies into job functions
  • support for both sync and async schedulers
  • support for auto_inject mode to automatically wrap all jobs

How to use

  1. Import
from apscheduler_dishka import (
    inject,
    setup_dishka,
)
from dishka import make_container, Provider, provide, Scope, FromDishka
  1. Create provider
class YourProvider(Provider):
    @provide(scope=Scope.REQUEST)
    def create_interactor(self) -> Interactor:
         ...
  1. Mark those of your job function parameters which are to be injected with FromDishka[] and decorate them using @inject
@inject
def job(
    data: str,
    interactor: FromDishka[Interactor],
):
    ...
  1. Create container
container = make_container(YourProvider())
  1. Setup dishka integration
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler_dishka import setup_dishka

scheduler = BlockingScheduler()
setup_dishka(container=container, scheduler=scheduler)
  1. Add jobs to scheduler
scheduler.add_job(
    job,
    trigger="interval",
    seconds=5,
    args=["args"],
)

Auto-inject mode

If you don't want to manually decorate each job with @inject, you can use auto_inject mode:

setup_dishka(
    container=container,
    scheduler=scheduler,
    auto_inject=True,
)

In this mode, all jobs will be automatically wrapped with dependency injection:

def job(
    data: str,
    interactor: FromDishka[Interactor],
):
    ...

scheduler.add_job(
    job,
    trigger="interval",
    seconds=5,
    args=["args"],
)

Async support

The library supports async schedulers:

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from dishka import make_async_container
from apscheduler_dishka import setup_dishka

scheduler = AsyncIOScheduler()
container = make_async_container(YourProvider())
setup_dishka(container=container, scheduler=scheduler)

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

apscheduler_dishka-1.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

apscheduler_dishka-1.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file apscheduler_dishka-1.1.0.tar.gz.

File metadata

  • Download URL: apscheduler_dishka-1.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for apscheduler_dishka-1.1.0.tar.gz
Algorithm Hash digest
SHA256 00021142d0e93eefed26a9a1403617996cc7113247a81c370b2e44b21f9ddc8b
MD5 78b7c4a2f851c9ea88f151fd16f336ee
BLAKE2b-256 3834bb7342bb55ecfc793708a15b9953cb8a5de400d3e1674ba59c5d9e52ecdb

See more details on using hashes here.

File details

Details for the file apscheduler_dishka-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: apscheduler_dishka-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for apscheduler_dishka-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e969f574665d662c9c24e1589db0c5e8983ca69ec3f54cdc1946114e7d110e6
MD5 f68f11ac8edd8869520a65f191130e44
BLAKE2b-256 efac8123feb558eb4c863f73d2c43e3fb63952c9c11a945e3663fa727f44e682

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