Skip to main content

Modern and fully typed declarative Di and IoC Framework

Project description

tests Docs

XDI Framework

XDI is a modern and declarative DI and IoC framework using pydantic for config and data.

Key features

  • Fast: Very high performance thanks to pydantic and preemptive wiring
  • Developer friendly: Declarative Container definition to take the "Magic" out of DI
  • Good compatibility: Can be used with almost every framework and supports async

Installation

pip install adnexus

Basic Example

from pathlib import Path
from datetime import datetime

from pydantic import BaseModel
from adnexus.containers import DeclarativeContainer
from adnexus.config.builtin import TOMLLoader
from adnexus.config import load_config
from adnexus.providers import FactoryProvider
from adnexus.markers import Provide
from adnexus.decorators import inject


class UpstreamInjectable:
    def __init__(self):
        self.time = datetime.now()

    def get_time(self):
        return self.time


class TestInjectable:
    def __init__(self, name: str, timer: Provide[UpstreamInjectable]):
        self.timer = timer
        self.name = name

    def greet(self):
        print(self.timer.get_time())
        return f"Hello {self.name}"


@inject
def test(greeter: Provide[TestInjectable]):
    print(greeter.greet())


class MyConfig(BaseModel):
    name: str


class MyContainer(DeclarativeContainer):
    # the loaded config can be accessed by calling MyContainer.config.<name>
    config = load_config(TOMLLoader(Path("/path/to/settings.toml")))

    injectables = [
        FactoryProvider(TestInjectable, config.name),
        FactoryProvider(UpstreamInjectable)
    ]


if __name__ == "__main__":
    container = MyContainer()
    container.wire([__name__])

    test()  # <-- dependencies are injected automatically

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

adnexus-0.1.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

adnexus-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file adnexus-0.1.2.tar.gz.

File metadata

  • Download URL: adnexus-0.1.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.7 Linux/6.5.0-1017-azure

File hashes

Hashes for adnexus-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a76f2b81ab3086209b3fe8b72ba5eb1a2c4d9d85032659216a20b6cbbaddefca
MD5 f6c2cca459d1c1daf2917e8748a66dff
BLAKE2b-256 c6c5f5a52c12bd5a31109ec142db51e005c01cd2ac60f536948930057af86a11

See more details on using hashes here.

File details

Details for the file adnexus-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: adnexus-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.7 Linux/6.5.0-1017-azure

File hashes

Hashes for adnexus-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38ec953b088cb00b038601a54d665c1ed6ca2f5007b0770e6cb9a7b7c710b958
MD5 b5f7544e38441cbb1f527a16bf40cdf0
BLAKE2b-256 ebf5bfcd13896091b4d5d4d4d0c0b2d6294625fefc3d11b4b2be73d13c7ff372

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