plugable dependency injection and result processing
Project description
in-n-out
Python dependency injection you can taste.
A lightweight dependency injection and result processing framework for Python using type hints. Emphasis is on simplicity, ease of use, and minimal impact on source code.
import in_n_out as ino
class Thing:
def __init__(self, name: str):
self.name = name
# use ino.inject to create a version of the function
# that will retrieve the required dependencies at call time
@ino.inject
def func(thing: Thing):
return thing.name
def give_me_a_thing() -> Thing:
return Thing("Thing")
# register a provider of Thing
ino.register_provider(give_me_a_thing)
print(func()) # prints "Thing"
def give_me_another_thing() -> Thing:
return Thing("Another Thing")
with ino.register_provider(give_me_another_thing, weight=10):
print(func()) # prints "Another Thing"
This also supports processing return values as well (injection of intentional side effects):
@ino.inject_processors
def func2(thing: Thing) -> str:
return thing.name
def greet_name(name: str):
print(f"Hello, {name}!")
ino.register_processor(greet_name)
func2(Thing('Bob')) # prints "Hello, Bob!"
Alternatives
Lots of other python DI frameworks exist, here are a few alternatives to consider:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
in_n_out-0.1.9.tar.gz
(25.3 kB
view details)
Built Distribution
in_n_out-0.1.9-py3-none-any.whl
(19.3 kB
view details)
File details
Details for the file in_n_out-0.1.9.tar.gz
.
File metadata
- Download URL: in_n_out-0.1.9.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89feb944e420faf42d3c2542145681b4d57144355932c2b859695fcdc4f9a2da |
|
MD5 | 1880ab3510b0eda5ff4313fb7b998388 |
|
BLAKE2b-256 | be4716507149b8099358657745203dd7db0bd890d91c92dffa83b6aa2a5bf5c9 |
File details
Details for the file in_n_out-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: in_n_out-0.1.9-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8ab404234a4bd76cc08a8f1f1a4861626d10dbc6eaed6b10ee261f886a4c1c8 |
|
MD5 | cc87b25cd2e179bfbe389dff2fd7eac5 |
|
BLAKE2b-256 | f95563d6a5becd5a019136070350d8533e5239add6e920b7dd016ad3048ee7da |