Skip to main content

rInject

A flexible (annotations or keys) but simple dependency injection library for Python 3.

Installation

pip install rinject

Usage

from rinject import Injector
from datetime import datetime


injector = Injector()


class A:
    def __init__(self, greeting: str):
        self.greeting = greeting

    def __call__(self, name: str):
        print(f"{self.greeting} {name}")


class B:
    def __init__(self, a: A, name: str):
        self.a = a
        self.name = name

    def __call__(self):
        self.a(self.name)


if __name__ == "__main__":
    injector.register_value("greeting", "Hello")
    injector.register_instance(A, A)
    injector.register_instance(B, B)
    injector.register_factory("name", lambda: "Steve@" + datetime.utcnow().isoformat())

    b = injector.resolve(B)
    b()  # outputs => Hello Steve

    b2 = injector.resolve(B)
    assert b is b2

Metadata

Release files for rInject 0.1.2

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

Source distribution (sdist)

Source distribution for rInject 0.1.2
File Size Uploaded
rinject-0.1.2.tar.gz 4.1 kB Details

Built distribution (wheel)

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

Total release size: 7.8 kB

Release files / rinject-0.1.2.tar.gz

Download URL rinject-0.1.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0a108b178030557467f3ed90a1f11159bb3017e2088ead8791b5b2ad97bf311
BLAKE2b-256 checksum
How to use checksums
f22bbe749951e5bd7ca418d66491c5da4972d3b234711deeea4e7f72cf175c74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / rInject-0.1.2-py3-none-any.whl

Download URL rInject-0.1.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2be86df98383e5963c4a6615a49dc551721255d90a5886da2bf2791ff382c32c
BLAKE2b-256 checksum
How to use checksums
4094c8c2bf57c3578ec4294a22ce0c42766266d23352440f301c0d5c652dcad2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

1 release file

0.1.0

1 release file

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