Skip to main content

dinjectorr

A simple dependency injector for Python.

Installation

pip install dinjectorr

Usage

Example 1:

from dinjectorr import inject

class A:
    def print_hello(self):
        print("Hello from A")

class B:
    @inject
    def __init__(self, a: A):
        self._a = a

    def print_hello(self):
        self._a.print_hello()

b = B()
b.print_hello()
# Output:
# Hello from A

Example 2:

from dinjectorr import Injector

class Client:
    def __init__(self, api_key: str):
        self._api_key = api_key

    def print_api_key(self):
        print(self._api_key)

Injector.register(Client, api_key="some_api_key")
client = Injector.get_instance(Client)
client.print_api_key()
# Output:
# some_api_key

Example 3:

from dinjectorr import inject, Injector

class Client:
    def __init__(self, api_key: str):
        self._api_key = api_key

    def print_api_key(self):
        print(self._api_key)

class CustomClient(Client):
    @inject
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

Injector.register(CustomClient, api_key="some_api_key")
custom_client = CustomClient()
custom_client.print_api_key()
# Output:
# some_api_key

Example 4:

from dinjectorr import inject, Injector

class Client:
    def __init__(self, api_key: str):
        self._api_key = api_key

    def print_api_key(self):
        print(self._api_key)

class CustomClient(Client):
    @inject
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

Injector.register(CustomClient, api_key="some_api_key")
custom_client = CustomClient(api_key="another_api_key")
custom_client.print_api_key()
# Output:
# another_api_key

Metadata

Release files for dinjectorr 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dinjectorr 0.1.8
File Size Uploaded
dinjectorr-0.1.8.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dinjectorr 0.1.8
File Interpreter ABI Platform
dinjectorr-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / dinjectorr-0.1.8.tar.gz

Download URL dinjectorr-0.1.8.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
13ef46324f4a52bb099cbe4e6f434fffd0d821d107fa0aae8d5d2ffb3bcae3c5
BLAKE2b-256 checksum
How to use checksums
bcdfee716b0e87457b312c51a109cba1aefe9dc87f73551742e5c2d77b0a50f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.4

Release files / dinjectorr-0.1.8-py3-none-any.whl

Download URL dinjectorr-0.1.8-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f78d4ecb31a84a4cbba9590f025de8ee7fcc9bcdd333abc5827fb99bc098e1d3
BLAKE2b-256 checksum
How to use checksums
c7116317ad7f37ee92a7b0754b8a3eec95592a930c690ada62ced43dd784b9ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page