Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

adnexus

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adnexus

Modern and fully typed declarative Di and IoC Framework

pipPyPI
Version
0.1.7
Maintainers
1

tests docs build

Adnexus Framework

Adnexus 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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts