Skip to main content

Dependency Injection library

Project description

AnyDI

[!IMPORTANT] Library renamed to anydi from pyxdi starting from version 0.19.0.

AnyDI is a lightweight Python Dependency Injection library that supports any synchronous or asynchronous code through type annotations (PEP 484).

CI codecov Documentation Status


Documentation

http://anydi.readthedocs.io/


Requirements

Python 3.8+

and optional dependencies:

  • anyio (for supporting synchronous resources with an asynchronous runtime)

Installation

Install using pip:

pip install anydi

or using poetry:

poetry add anydi

Quick Example

app.py

from anydi import auto, Container

container = Container()
container.register(str, lambda: "Hello, world!", scope="singleton")


@container.provider(scope="singleton")
def message() -> str:
    return "Hello, world!"


@container.inject
def say_hello(message: str = auto()) -> None:
    print(message)


if __name__ == "__main__":
    say_hello()

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

anydi-0.19.0.tar.gz (16.0 kB view hashes)

Uploaded Source

Built Distribution

anydi-0.19.0-py3-none-any.whl (19.4 kB view hashes)

Uploaded Python 3

Supported by

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