Skip to main content

modern-di integration for Celery

Project description

modern-di-celery

Modern-DI integration for Celery 5.x.

Quickstart

import typing

from celery import Celery
from modern_di import Container, Group, Scope, providers
from modern_di_celery import DITask, FromDI, setup_di


class Settings:
    def __init__(self) -> None:
        self.greeting = "hello"


class Dependencies(Group):
    settings = providers.Factory(scope=Scope.APP, creator=Settings)


app = Celery("myapp", broker="redis://localhost", task_cls=DITask)
setup_di(app, Container(groups=[Dependencies], validate=True))


@app.task
def greet(name: str, settings: typing.Annotated[Settings, FromDI(Dependencies.settings)]) -> str:
    return f"{settings.greeting}, {name}"

With task_cls=DITask every task is injected; alternatively decorate individual tasks with @inject. See the documentation.

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

modern_di_celery-2.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

modern_di_celery-2.0.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file modern_di_celery-2.0.1.tar.gz.

File metadata

  • Download URL: modern_di_celery-2.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 modern_di_celery-2.0.1.tar.gz
Algorithm Hash digest
SHA256 175cdcc709b9540250d53e34a72b293b3f4b4a6ff8d05467045804d4bc9ea812
MD5 cf4d6e93980865a046d8b092daff09be
BLAKE2b-256 88c0230825e647aaeb02a20c1f6049832e32133b2633055f5bf3c728167816b1

See more details on using hashes here.

File details

Details for the file modern_di_celery-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: modern_di_celery-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 modern_di_celery-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 21b0c9d443835523f08695571b8ebb8608a168f4bf3795c4dc14ec2e44d813cf
MD5 11a63a904ce04258941e141a2eafe222
BLAKE2b-256 2e3c93f9ab18f0914af010e317ea95a587002f00044bd8ec0bdecd88904efd33

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