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:
Metadata
Release files for in-n-out 0.2.1
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 |
|---|---|---|---|---|
| in_n_out-0.2.1.tar.gz | 26.0 kB | Without provenance | Details for in_n_out-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| in_n_out-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for in_n_out-0.2.1-py3-none-any.whl |
Total release size: 46.0 kB
Release files / in_n_out-0.2.1.tar.gz
| Download URL | in_n_out-0.2.1.tar.gz |
|---|---|
| Size | 26.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43cde2b7de981d41a6d70618a2b7bd989481095922a53ead4dc75f2bbd5dffea
|
|
BLAKE2b-256 checksum How to use checksums |
af0807edfac98a38ab0208557524cbdd94a296f565b0558417ccb2c03d14a6ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / in_n_out-0.2.1-py3-none-any.whl
| Download URL | in_n_out-0.2.1-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
343e81edb27cf41ec946134a92964f408465abdf6a065c6c55fe96f53bc3c8b7
|
|
BLAKE2b-256 checksum How to use checksums |
3b06711a4d105ad3d01d3ef351a1039bb5cc517a57dbf377d7da9a0808e34c77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for in-n-out 0.2.1
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.