# python-injection
[![CI](https://github.com/100nm/python-injection/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-injection)
[![PyPI](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
Fast and easy dependency injection framework.
## Installation
⚠️ _Requires Python 3.12 or higher_
```bash
pip install python-injection
```
## Motivations
1. Easy to use
2. No impact on class and function definitions
3. Easily interchangeable dependencies _(depending on the runtime environment, for example)_
4. No prerequisites
## Quick start
Simply apply the decorators and the package takes care of the rest.
```python
from injection import injectable, inject, singleton
@singleton
class Printer:
def __init__(self):
self.history = []
def print(self, message: str):
self.history.append(message)
print(message)
@injectable
class Service:
def __init__(self, printer: Printer):
self.printer = printer
def hello(self):
self.printer.print("Hello world!")
@inject
def main(service: Service):
service.hello()
if __name__ == "__main__":
main()
```
## Resources
* [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)
* [**Testing**](https://github.com/100nm/python-injection/tree/prod/documentation/testing.md)
* [**Advanced usage**](https://github.com/100nm/python-injection/tree/prod/documentation/advanced-usage.md)
* [**Utils**](https://github.com/100nm/python-injection/tree/prod/documentation/utils.md)
* [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations.md)
* [**Concrete example**](https://github.com/100nm/python-injection/tree/prod/documentation/example)
Raw data
{
"_id": null,
"home_page": "https://github.com/100nm/python-injection",
"name": "python-injection",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.12",
"maintainer_email": null,
"keywords": "dependencies, dependency, inject, injection",
"author": "remimd",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/b5/ab/7820627b98b6de117dfbc2423586063e1e708e72a4208d7e539eebd8ff45/python_injection-0.11.0.tar.gz",
"platform": null,
"description": "# python-injection\n\n[![CI](https://github.com/100nm/python-injection/actions/workflows/ci.yml/badge.svg)](https://github.com/100nm/python-injection)\n[![PyPI](https://img.shields.io/pypi/v/python-injection.svg?color=blue)](https://pypi.org/project/python-injection/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\nFast and easy dependency injection framework.\n\n## Installation\n\n\u26a0\ufe0f _Requires Python 3.12 or higher_\n\n```bash\npip install python-injection\n```\n\n## Motivations\n\n1. Easy to use\n2. No impact on class and function definitions\n3. Easily interchangeable dependencies _(depending on the runtime environment, for example)_\n4. No prerequisites\n\n## Quick start\n\nSimply apply the decorators and the package takes care of the rest.\n\n```python\nfrom injection import injectable, inject, singleton\n\n@singleton\nclass Printer:\n def __init__(self):\n self.history = []\n\n def print(self, message: str):\n self.history.append(message)\n print(message)\n\n@injectable\nclass Service:\n def __init__(self, printer: Printer):\n self.printer = printer\n\n def hello(self):\n self.printer.print(\"Hello world!\")\n\n@inject\ndef main(service: Service):\n service.hello()\n\nif __name__ == \"__main__\":\n main()\n```\n\n## Resources\n\n* [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)\n* [**Testing**](https://github.com/100nm/python-injection/tree/prod/documentation/testing.md)\n* [**Advanced usage**](https://github.com/100nm/python-injection/tree/prod/documentation/advanced-usage.md)\n* [**Utils**](https://github.com/100nm/python-injection/tree/prod/documentation/utils.md)\n* [**Integrations**](https://github.com/100nm/python-injection/tree/prod/documentation/integrations.md)\n* [**Concrete example**](https://github.com/100nm/python-injection/tree/prod/documentation/example)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Fast and easy dependency injection framework.",
"version": "0.11.0",
"project_urls": {
"Homepage": "https://github.com/100nm/python-injection",
"Repository": "https://github.com/100nm/python-injection"
},
"split_keywords": [
"dependencies",
" dependency",
" inject",
" injection"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "61fae37c14bbefd8588e2e20bf52f237270d3cc33dd4d4ccd51d019e08af152f",
"md5": "a98306744643b6174b4b8f5ea48c76e3",
"sha256": "afd6adbda8560f0e9541959b77f78440bdedf37954c4f12bfe84d014650c8798"
},
"downloads": -1,
"filename": "python_injection-0.11.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a98306744643b6174b4b8f5ea48c76e3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.12",
"size": 19691,
"upload_time": "2024-11-04T11:09:43",
"upload_time_iso_8601": "2024-11-04T11:09:43.523151Z",
"url": "https://files.pythonhosted.org/packages/61/fa/e37c14bbefd8588e2e20bf52f237270d3cc33dd4d4ccd51d019e08af152f/python_injection-0.11.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b5ab7820627b98b6de117dfbc2423586063e1e708e72a4208d7e539eebd8ff45",
"md5": "8372910f1e64a155b48a8a9c84af78ed",
"sha256": "fb9691a9c8aae576693fcfb30c333ae81391458959a3816ab0b5d79b87afb570"
},
"downloads": -1,
"filename": "python_injection-0.11.0.tar.gz",
"has_sig": false,
"md5_digest": "8372910f1e64a155b48a8a9c84af78ed",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.12",
"size": 14851,
"upload_time": "2024-11-04T11:09:44",
"upload_time_iso_8601": "2024-11-04T11:09:44.737188Z",
"url": "https://files.pythonhosted.org/packages/b5/ab/7820627b98b6de117dfbc2423586063e1e708e72a4208d7e539eebd8ff45/python_injection-0.11.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-04 11:09:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "100nm",
"github_project": "python-injection",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-injection"
}