# rInject
A flexible (annotations or keys) but simple dependency injection library for Python 3.
## Installation
```pip install rinject```
## Usage
```python
from rinject import Injector
from datetime import datetime
injector = Injector()
class A:
def __init__(self, greeting: str):
self.greeting = greeting
def __call__(self, name: str):
print(f"{self.greeting} {name}")
class B:
def __init__(self, a: A, name: str):
self.a = a
self.name = name
def __call__(self):
self.a(self.name)
if __name__ == "__main__":
injector.register_value("greeting", "Hello")
injector.register_instance(A, A)
injector.register_instance(B, B)
injector.register_factory("name", lambda: "Steve@" + datetime.utcnow().isoformat())
b = injector.resolve(B)
b() # outputs => Hello Steve
b2 = injector.resolve(B)
assert b is b2
```
Raw data
{
"_id": null,
"home_page": "https://github.com/stevemccartney/rinject",
"name": "rInject",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "dependency injection inject injector di dic",
"author": "Steve McCartney",
"author_email": "python@reconvergent.com",
"download_url": "https://files.pythonhosted.org/packages/f2/2b/be749951e5bd7ca418d66491c5da4972d3b234711deeea4e7f72cf175c74/rinject-0.1.2.tar.gz",
"platform": null,
"description": "# rInject\n\nA flexible (annotations or keys) but simple dependency injection library for Python 3.\n\n\n## Installation\n\n```pip install rinject```\n\n\n## Usage\n\n```python\nfrom rinject import Injector\nfrom datetime import datetime\n\n\ninjector = Injector()\n\n\nclass A:\n def __init__(self, greeting: str):\n self.greeting = greeting\n\n def __call__(self, name: str):\n print(f\"{self.greeting} {name}\")\n\n\nclass B:\n def __init__(self, a: A, name: str):\n self.a = a\n self.name = name\n\n def __call__(self):\n self.a(self.name)\n\n\nif __name__ == \"__main__\":\n injector.register_value(\"greeting\", \"Hello\")\n injector.register_instance(A, A)\n injector.register_instance(B, B)\n injector.register_factory(\"name\", lambda: \"Steve@\" + datetime.utcnow().isoformat())\n\n b = injector.resolve(B)\n b() # outputs => Hello Steve\n\n b2 = injector.resolve(B)\n assert b is b2\n```\n\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "A flexible (annotations or keys) but simple dependency injection library for Python 3.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/stevemccartney/rinject"
},
"split_keywords": [
"dependency",
"injection",
"inject",
"injector",
"di",
"dic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4094c8c2bf57c3578ec4294a22ce0c42766266d23352440f301c0d5c652dcad2",
"md5": "f015e8fe30e1200f1f600281c5423fa8",
"sha256": "2be86df98383e5963c4a6615a49dc551721255d90a5886da2bf2791ff382c32c"
},
"downloads": -1,
"filename": "rInject-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f015e8fe30e1200f1f600281c5423fa8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 3668,
"upload_time": "2024-05-01T07:08:43",
"upload_time_iso_8601": "2024-05-01T07:08:43.129691Z",
"url": "https://files.pythonhosted.org/packages/40/94/c8c2bf57c3578ec4294a22ce0c42766266d23352440f301c0d5c652dcad2/rInject-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f22bbe749951e5bd7ca418d66491c5da4972d3b234711deeea4e7f72cf175c74",
"md5": "9ad67c3d98b499043ca4597f108783c0",
"sha256": "f0a108b178030557467f3ed90a1f11159bb3017e2088ead8791b5b2ad97bf311"
},
"downloads": -1,
"filename": "rinject-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "9ad67c3d98b499043ca4597f108783c0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4130,
"upload_time": "2024-05-01T07:08:44",
"upload_time_iso_8601": "2024-05-01T07:08:44.503366Z",
"url": "https://files.pythonhosted.org/packages/f2/2b/be749951e5bd7ca418d66491c5da4972d3b234711deeea4e7f72cf175c74/rinject-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-01 07:08:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stevemccartney",
"github_project": "rinject",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "rinject"
}