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.0.tar.gz (3.3 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.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modern_di_celery-2.0.0.tar.gz
  • Upload date:
  • Size: 3.3 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.0.tar.gz
Algorithm Hash digest
SHA256 d40320898c3708e8150e15c57d2007ef69d5b67415e239c134c080315a282812
MD5 cce93329d4949b6713a55e4d7e665492
BLAKE2b-256 15f147a804a08c2795690cec44a72f779edf0f3fa065407ed483753a4ad69bb9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: modern_di_celery-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 589e54cb9aeda56853d8908c401219e9a27270b96f1d89c6c461239665af59da
MD5 b67e365c39a908dfbc494031b4149aec
BLAKE2b-256 7b0776ec25f193eac017b0313935da4f0f566891385579255222d97416961740

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