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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| injkt-0.1.0.tar.gz | 3.4 kB | Without provenance | Details for injkt-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| injkt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for injkt-0.1.0-py3-none-any.whl |
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
|
Security for injkt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.