This release is a pre-release and may not be stable for production use.
NOTE: This project is in ALPHA state
jacked ~ python on roids
- A light and easy to use dependency injection framework.
- Inject objects, functions, classes or lists containing any of these.
- Let jacked automatically discover your injectables in a package.
- Loose coupling on the juice!
- Excellent for making your code testable!
Install
pip install jacked
Usage
Inject instances
To inject instances, mark a class with the injectable decorator:
from jacked import injectable
@injectable
class Cat:
def sound(self):
return 'meow'
You can now inject it in a function anywhere. Place the inject decorator on
top of the function or method. Let jacked know what type to inject by type
hinting your parameters:
@inject
def what_sound_does_it_make(cat: Cat):
print(cat.sound())
what_sound_does_it_make()
Inject functions
Injecting functions works similarly. Just make sure that your function has the proper type hints:
@injectable
def some_func(x: int, y: int) -> str:
return f'The sum of {x} and {y} is {x + y}'
And like with instances, inject as follows:
@inject
def do_something(func: Callable[[int, int], str]):
print(func(21, 21))
do_something()
Inject classes
Assuming that we have the same Cat injectable like before, we can inject
that class as follows:
from typing import Type
@inject
def do_something(cat_type: Type[Cat]):
print(cat_type.__name__)
do_something()
Inject lists
Let's suppose that we have the following two injectables of the same parent:
class Animal(ABC):
@abstractmethod
def sound(self):
raise NotImplementedError
@injectable
class Cat(Animal):
def sound(self):
return 'meow'
@injectable
class Dog(Animal):
def sound(self):
return 'bark'
You can now inject them in a list:
@inject
def what_sound_does_it_make(animals: List[Animal]):
for animal in animals:
print(f'The {animal.__class__.__name__} does {animal.sound()}')
what_sound_does_it_make()
You could have also injected a list of classes or functions by hinting
List[Type[...]] or List[Callable[...]] (the ... replaced by your
injection target).
Singletons
You can annotate an injectable as singleton, meaning that if the injectable is a class, only one instance is ever injected:
@injectable(singleton=True)
class Dog(Animal):
def sound(self):
return 'bark'
Auto discovery
You can let jacked discover injectables in some package using the
discover function:
from jacked import discover
discover('path/to/your/package')
All python modules in that package are imported and the injectables are registered.
Metadata
Release files for jacked 1.0.0a3
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 | |
|---|---|---|---|---|
| jacked-1.0.0a3.tar.gz | 11.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jacked-1.0.0a3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.3 kB
Release files / jacked-1.0.0a3.tar.gz
| Download URL | jacked-1.0.0a3.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d13491f05e126df19e18be7406a43cb89464bc28b22544a913f4107493da47e
|
|
BLAKE2b-256 checksum How to use checksums |
40fdcba9492f76fb4ef0b11d61fa9244174fea57131081fff3cd324411d58d84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Release files / jacked-1.0.0a3-py3-none-any.whl
| Download URL | jacked-1.0.0a3-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c60b5db33039ebf40af3b86b9bbf8126801afb3f858a21cb5122cfa5322414fd
|
|
BLAKE2b-256 checksum How to use checksums |
11ded82585bac9e53970486110738c5057f0a7823f40b18d87871018ed0da361
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Security for jacked 1.0.0a3
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.