Name | in-n-out JSON |
Version |
0.1.9
JSON |
| download |
home_page | |
Summary | plugable dependency injection and result processing |
upload_time | 2023-10-10 00:55:41 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.8 |
license | BSD 3-Clause License |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# in-n-out
[![License](https://img.shields.io/pypi/l/in-n-out.svg?color=green)](https://github.com/pyapp-kit/in-n-out/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/in-n-out.svg?color=green)](https://pypi.org/project/in-n-out)
[![Python Version](https://img.shields.io/pypi/pyversions/in-n-out.svg?color=green)](https://python.org)
[![CI](https://github.com/pyapp-kit/in-n-out/actions/workflows/ci.yml/badge.svg)](https://github.com/pyapp-kit/in-n-out/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/pyapp-kit/in-n-out/branch/main/graph/badge.svg)](https://app.codecov.io/gh/pyapp-kit/in-n-out)
[![Benchmarks](https://img.shields.io/badge/⏱-codspeed-%23FF7B53)](https://codspeed.io/pyapp-kit/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.
```python
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):
```python
@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:
- <https://github.com/ets-labs/python-dependency-injector>
- <https://github.com/google/pinject>
- <https://github.com/ivankorobkov/python-inject>
- <https://github.com/alecthomas/injector>
- <https://github.com/Finistere/antidote>
- <https://github.com/dry-python/returns>
- <https://github.com/adriangb/di>
Raw data
{
"_id": null,
"home_page": "",
"name": "in-n-out",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "Talley Lambert <talley.lambert@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/be/47/16507149b8099358657745203dd7db0bd890d91c92dffa83b6aa2a5bf5c9/in_n_out-0.1.9.tar.gz",
"platform": null,
"description": "# in-n-out\n\n[![License](https://img.shields.io/pypi/l/in-n-out.svg?color=green)](https://github.com/pyapp-kit/in-n-out/raw/main/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/in-n-out.svg?color=green)](https://pypi.org/project/in-n-out)\n[![Python Version](https://img.shields.io/pypi/pyversions/in-n-out.svg?color=green)](https://python.org)\n[![CI](https://github.com/pyapp-kit/in-n-out/actions/workflows/ci.yml/badge.svg)](https://github.com/pyapp-kit/in-n-out/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/pyapp-kit/in-n-out/branch/main/graph/badge.svg)](https://app.codecov.io/gh/pyapp-kit/in-n-out)\n[![Benchmarks](https://img.shields.io/badge/\u23f1-codspeed-%23FF7B53)](https://codspeed.io/pyapp-kit/in-n-out)\n\nPython dependency injection you can taste.\n\nA lightweight dependency injection and result processing framework\nfor Python using type hints. Emphasis is on simplicity, ease of use,\nand minimal impact on source code.\n\n```python\nimport in_n_out as ino\n\n\nclass Thing:\n def __init__(self, name: str):\n self.name = name\n\n\n# use ino.inject to create a version of the function\n# that will retrieve the required dependencies at call time\n@ino.inject\ndef func(thing: Thing):\n return thing.name\n\n\ndef give_me_a_thing() -> Thing:\n return Thing(\"Thing\")\n\n\n# register a provider of Thing\nino.register_provider(give_me_a_thing)\nprint(func()) # prints \"Thing\"\n\n\ndef give_me_another_thing() -> Thing:\n return Thing(\"Another Thing\")\n\n\nwith ino.register_provider(give_me_another_thing, weight=10):\n print(func()) # prints \"Another Thing\"\n```\n\nThis also supports processing *return* values as well\n(injection of intentional side effects):\n\n```python\n\n@ino.inject_processors\ndef func2(thing: Thing) -> str:\n return thing.name\n\ndef greet_name(name: str):\n print(f\"Hello, {name}!\")\n\nino.register_processor(greet_name)\n\nfunc2(Thing('Bob')) # prints \"Hello, Bob!\"\n```\n\n### Alternatives\n\nLots of other python DI frameworks exist, here are a few alternatives to consider:\n\n- <https://github.com/ets-labs/python-dependency-injector>\n- <https://github.com/google/pinject>\n- <https://github.com/ivankorobkov/python-inject>\n- <https://github.com/alecthomas/injector>\n- <https://github.com/Finistere/antidote>\n- <https://github.com/dry-python/returns>\n- <https://github.com/adriangb/di>\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "plugable dependency injection and result processing",
"version": "0.1.9",
"project_urls": {
"documentation": "https://pyapp-kit.github.io/in-n-out",
"homepage": "https://github.com/pyapp-kit/in-n-out",
"repository": "https://github.com/pyapp-kit/in-n-out"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f95563d6a5becd5a019136070350d8533e5239add6e920b7dd016ad3048ee7da",
"md5": "cc87b25cd2e179bfbe389dff2fd7eac5",
"sha256": "a8ab404234a4bd76cc08a8f1f1a4861626d10dbc6eaed6b10ee261f886a4c1c8"
},
"downloads": -1,
"filename": "in_n_out-0.1.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cc87b25cd2e179bfbe389dff2fd7eac5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 19263,
"upload_time": "2023-10-10T00:55:39",
"upload_time_iso_8601": "2023-10-10T00:55:39.564898Z",
"url": "https://files.pythonhosted.org/packages/f9/55/63d6a5becd5a019136070350d8533e5239add6e920b7dd016ad3048ee7da/in_n_out-0.1.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "be4716507149b8099358657745203dd7db0bd890d91c92dffa83b6aa2a5bf5c9",
"md5": "1880ab3510b0eda5ff4313fb7b998388",
"sha256": "89feb944e420faf42d3c2542145681b4d57144355932c2b859695fcdc4f9a2da"
},
"downloads": -1,
"filename": "in_n_out-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "1880ab3510b0eda5ff4313fb7b998388",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 25273,
"upload_time": "2023-10-10T00:55:41",
"upload_time_iso_8601": "2023-10-10T00:55:41.146733Z",
"url": "https://files.pythonhosted.org/packages/be/47/16507149b8099358657745203dd7db0bd890d91c92dffa83b6aa2a5bf5c9/in_n_out-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-10 00:55:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pyapp-kit",
"github_project": "in-n-out",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "in-n-out"
}