Nurse
=====
.. image:: https://img.shields.io/badge/license-public%20domain-ff69b4.svg
:target: https://github.com/ZeroGachis/nurse#license
.. image:: https://img.shields.io/badge/pypi-v0.3.1-blue.svg
:target: https://pypi.org/project/nurse/
Outline
~~~~~~~
1. `Overview <https://github.com/ZeroGachis/nurse#overview>`_
2. `Installation <https://github.com/ZeroGachis/nurse#installation>`_
3. `Usage <https://github.com/ZeroGachis/nurse#usage>`_
4. `License <https://github.com/ZeroGachis/nurse#license>`_
Overview
~~~~~~~~
**Nurse** is a **dependency injection framework** with a small API that uses
type annotations to manage dependencies in your codebase.
Installation
~~~~~~~~~~~~
**Nurse** is a Python3-only module that you can install via `Poetry <https://github.com/sdispater/poetry>`_
.. code:: sh
poetry add nurse
It can also be installed with `pip`
.. code:: sh
pip3 install nurse
Usage
~~~~~
**Nurse** stores the available dependencies into a service catalog, that needs to be
filled-in generally at the startup of your application.
.. code:: python3
import nurse
# A user defined class that will be used accross your application
class Player:
@property
def name(self) -> str:
return "Leeroy Jenkins"
# Now, add it to nurse service catalog in order to use it later in your application
nurse.serve(Player())
By default, dependencies are referenced by their concrete type, but you can also serve them
via one of their parent class.
.. code:: python3
import nurse
class Animal:
pass
class AngryAnimal(Animal):
@property
def roar(self) -> str:
return "Grrr! 🦁"
nurse.serve(AngryAnimal(), through=Animal)
Once you filled-in the service catalog with your different components, your can declare them as dependencies
to any of your class.
.. code:: python3
@nurse.inject("player")
class Game:
player: Player
enemy: Animal
def welcome_hero(self):
print(f"Welcome {self.player.name} !")
def summon_monster(self):
print(self.enemy.roar)
Game = Game()
game.welcome_hero()
# Welcome Leeroy Jenkins !
game.summon_monster()
# Grrr! 🦁
Or in any function
.. code:: python3
@nurse.inject('enemy')
def summon_monster(enemy: Animal):
print(enemy.roar)
summon_monster()
# Grrr! 🦁
And it works with async function as well !
.. code:: python3
import asyncio
@nurse.inject('enemy')
async def summon_monster(enemy: Animal):
print(enemy.roar)
asyncio.run(summon_monster())
# Grrr! 🦁
Finally, you can also retrieve a service without using a decorator
.. code:: python3
enemy = nurse.get(Animal)
print(enemy.roar)
# Grrr! 🦁
License
~~~~~~~
**Nurse** is released into the Public Domain. 🎉
Raw data
{
"_id": null,
"home_page": "https://github.com/ZeroGachis/nurse",
"name": "nurse",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "dependency,injection",
"author": "ducdetronquito",
"author_email": "g.paulet@zero-gachis.com",
"download_url": "https://files.pythonhosted.org/packages/33/47/eddc9509484589f79416ca1343e24ce74f060ad9224ef81488e782226900/nurse-0.5.1.tar.gz",
"platform": null,
"description": "Nurse\n=====\n\n.. image:: https://img.shields.io/badge/license-public%20domain-ff69b4.svg\n :target: https://github.com/ZeroGachis/nurse#license\n\n\n.. image:: https://img.shields.io/badge/pypi-v0.3.1-blue.svg\n :target: https://pypi.org/project/nurse/\n\n\nOutline\n~~~~~~~\n\n1. `Overview <https://github.com/ZeroGachis/nurse#overview>`_\n2. `Installation <https://github.com/ZeroGachis/nurse#installation>`_\n3. `Usage <https://github.com/ZeroGachis/nurse#usage>`_\n4. `License <https://github.com/ZeroGachis/nurse#license>`_\n\n\nOverview\n~~~~~~~~\n\n\n**Nurse** is a **dependency injection framework** with a small API that uses\ntype annotations to manage dependencies in your codebase.\n\n\nInstallation\n~~~~~~~~~~~~\n\n**Nurse** is a Python3-only module that you can install via `Poetry <https://github.com/sdispater/poetry>`_\n\n.. code:: sh\n\n poetry add nurse\n\n\nIt can also be installed with `pip`\n\n.. code:: sh\n\n pip3 install nurse\n\n\nUsage\n~~~~~\n\n**Nurse** stores the available dependencies into a service catalog, that needs to be\nfilled-in generally at the startup of your application.\n\n.. code:: python3\n\n import nurse\n \n # A user defined class that will be used accross your application\n class Player:\n \n @property\n def name(self) -> str:\n return \"Leeroy Jenkins\"\n\n # Now, add it to nurse service catalog in order to use it later in your application\n nurse.serve(Player())\n\nBy default, dependencies are referenced by their concrete type, but you can also serve them\nvia one of their parent class.\n\n.. code:: python3\n\n import nurse\n\n class Animal:\n pass\n\n class AngryAnimal(Animal):\n\n @property\n def roar(self) -> str:\n return \"Grrr! \ud83e\udd81\"\n\n nurse.serve(AngryAnimal(), through=Animal)\n\nOnce you filled-in the service catalog with your different components, your can declare them as dependencies\nto any of your class.\n\n.. code:: python3\n\n @nurse.inject(\"player\")\n class Game:\n player: Player\n enemy: Animal\n\n def welcome_hero(self):\n print(f\"Welcome {self.player.name} !\")\n \n def summon_monster(self):\n print(self.enemy.roar)\n\n Game = Game()\n game.welcome_hero()\n # Welcome Leeroy Jenkins !\n game.summon_monster()\n # Grrr! \ud83e\udd81\n\n\nOr in any function\n\n.. code:: python3\n\n @nurse.inject('enemy')\n def summon_monster(enemy: Animal):\n print(enemy.roar)\n\n summon_monster()\n # Grrr! \ud83e\udd81\n\n\nAnd it works with async function as well !\n\n.. code:: python3\n\n import asyncio\n\n @nurse.inject('enemy')\n async def summon_monster(enemy: Animal):\n print(enemy.roar)\n\n asyncio.run(summon_monster())\n # Grrr! \ud83e\udd81\n\n\nFinally, you can also retrieve a service without using a decorator\n\n.. code:: python3\n\n enemy = nurse.get(Animal)\n print(enemy.roar)\n # Grrr! \ud83e\udd81\n\n\nLicense\n~~~~~~~\n\n**Nurse** is released into the Public Domain. \ud83c\udf89\n",
"bugtrack_url": null,
"license": "",
"summary": "A thoughtful dependency injection framework \ud83d\udc89",
"version": "0.5.1",
"project_urls": {
"Homepage": "https://github.com/ZeroGachis/nurse",
"Repository": "https://github.com/ZeroGachis/nurse"
},
"split_keywords": [
"dependency",
"injection"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9eca97a5fa4eb5e1ea0789a66ec38c52b1414d2eaf0580de48156d257fdfc8cc",
"md5": "0f43e5b234e181ae3aa6285c2215bd9f",
"sha256": "ff3f111b6c845510bbca1dc2ee26fce2c8d8df1182377823a72936fe392955da"
},
"downloads": -1,
"filename": "nurse-0.5.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0f43e5b234e181ae3aa6285c2215bd9f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 4159,
"upload_time": "2023-11-16T10:30:42",
"upload_time_iso_8601": "2023-11-16T10:30:42.460605Z",
"url": "https://files.pythonhosted.org/packages/9e/ca/97a5fa4eb5e1ea0789a66ec38c52b1414d2eaf0580de48156d257fdfc8cc/nurse-0.5.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3347eddc9509484589f79416ca1343e24ce74f060ad9224ef81488e782226900",
"md5": "a957107f239059f73e22671a7c4cf6d8",
"sha256": "59aeb4e809f14dac10f9799d0e5d2f3594cfa2f19e1bf966499c7dfdb7378548"
},
"downloads": -1,
"filename": "nurse-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "a957107f239059f73e22671a7c4cf6d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 3315,
"upload_time": "2023-11-16T10:30:43",
"upload_time_iso_8601": "2023-11-16T10:30:43.757495Z",
"url": "https://files.pythonhosted.org/packages/33/47/eddc9509484589f79416ca1343e24ce74f060ad9224ef81488e782226900/nurse-0.5.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-16 10:30:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ZeroGachis",
"github_project": "nurse",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nurse"
}