Skip to main content

Injkt (Dependency injection injktion)

Your simple python DI library built with good intentions.

Install

pip install injkt

Why?

Good question.

How?

import typing as ty

from injkt import Bind, Config, Injectable, Injktor, inject_args_deps


class IMailService(ty.Protocol):
    def send_mail(self, subject: str, to: str) -> None:
        ...


class SmtpMailService(IMailService):
    def send_mail(self, subject: str, to: str) -> None:
        raise NotImplementedError()


injktor = Injktor(
    Config(
        {
            Bind(IMailService, SmtpMailService),
        }
    )
)


@inject_args_deps
def business_logic(mail_service=Injectable(IMailService)):
    mail_service.send_mail("Hello", "world")


business_logic()

Class Based

from injktor import inject_attr_deps

@inject_attr_deps
class BusinessLogic:
    mail_service = Injectable(IMailService)

    def do_business_logic(self) -> None:
        self.mail_service.send_mail("Hello", "world")


BusinessLogic().do_business_logic()

Class based lazy injection

from injktor import InjktLazy

class BusinessLogic(InjktLazy):
    mail_service = Injectable(IMailService)

    def do_business_logic(self) -> None:
        self.mail_service.send_mail("Hello", "world")


BusinessLogic().do_business_logic()

Re-init dependencies

injktor = Injktor(
    Config(
        {
            Bind(IMailService, SmtpMailService, always_reinit=True),
        }
    )
)

Enabling always_reinit will re-initialize the dependency on each call. NOTE: It won't be re-initialized in the same class if you aren't using InjktLazy

Release files for injkt 0.1.0

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

Source distribution (sdist)

Source distribution for injkt 0.1.0
File Size Uploaded
injkt-0.1.0.tar.gz 3.4 kB Details

Built distribution (wheel)

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

Total release size: 9.0 kB

Release files / injkt-0.1.0.tar.gz

Download URL injkt-0.1.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c01201237fbbc8c5334043d60fb08bb23a9486ab161a91d2d41c5dd70d9a6520
BLAKE2b-256 checksum
How to use checksums
889670c0f0e8316885485a00c5c9f4161a10f7511e357302d5d06e8f4c88d960
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.6 Darwin/23.1.0

Release files / injkt-0.1.0-py3-none-any.whl

Download URL injkt-0.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d46052c32a1270b08b3ee371ccd3ced5f32596ccca2fde093371a4c92212c0b1
BLAKE2b-256 checksum
How to use checksums
28793387a808771e5541e907841661f6f6dd41412115a262ce02f16657eb3903
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.9.6 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

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