# 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/f2/1d/f3729a983ade18a63e6bafbee0c50f6ffb28bae7447d8ad2c382df95f3e3/python_injection-0.12.1.post0.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.12.1.post0",
"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": "d5f4fb5ef480dbf5622f53cda42ee501b08aa304ac50a1a337adbf7fa0fe698f",
"md5": "b8592ad2610a1fac5cca98acb30abb7d",
"sha256": "1e816d72f6ba17ea828694be761a6b95a645060ce637a5e81791058a4f0c4f79"
},
"downloads": -1,
"filename": "python_injection-0.12.1.post0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b8592ad2610a1fac5cca98acb30abb7d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.12",
"size": 20987,
"upload_time": "2025-01-08T11:58:18",
"upload_time_iso_8601": "2025-01-08T11:58:18.532014Z",
"url": "https://files.pythonhosted.org/packages/d5/f4/fb5ef480dbf5622f53cda42ee501b08aa304ac50a1a337adbf7fa0fe698f/python_injection-0.12.1.post0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f21df3729a983ade18a63e6bafbee0c50f6ffb28bae7447d8ad2c382df95f3e3",
"md5": "1b7b5f9b1f06f35f9c78b6c2e39e7f82",
"sha256": "c4714a72f3eafa34d1c32c128a7c91247e4399cbdba2a24da2a7cc26ccdc3176"
},
"downloads": -1,
"filename": "python_injection-0.12.1.post0.tar.gz",
"has_sig": false,
"md5_digest": "1b7b5f9b1f06f35f9c78b6c2e39e7f82",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.12",
"size": 15177,
"upload_time": "2025-01-08T11:58:20",
"upload_time_iso_8601": "2025-01-08T11:58:20.647364Z",
"url": "https://files.pythonhosted.org/packages/f2/1d/f3729a983ade18a63e6bafbee0c50f6ffb28bae7447d8ad2c382df95f3e3/python_injection-0.12.1.post0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-08 11:58:20",
"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"
}