Skip to main content
https://img.shields.io/badge/license-public%20domain-ff69b4.svg https://img.shields.io/badge/pypi-v0.3.1-blue.svg

Outline

  1. Overview

  2. Installation

  3. Usage

  4. 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

poetry add nurse

It can also be installed with pip

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.

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.

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.

@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

@nurse.inject('enemy')
def summon_monster(enemy: Animal):
    print(enemy.roar)

summon_monster()
# Grrr! 🦁

And it works with async function as well !

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

enemy = nurse.get(Animal)
print(enemy.roar)
# Grrr! 🦁

License

Nurse is released into the Public Domain. 🎉

Release files for nurse 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nurse 0.5.1
File Size Uploaded
nurse-0.5.1.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nurse 0.5.1
File Interpreter ABI Platform
nurse-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / nurse-0.5.1.tar.gz

Download URL nurse-0.5.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
59aeb4e809f14dac10f9799d0e5d2f3594cfa2f19e1bf966499c7dfdb7378548
BLAKE2b-256 checksum
How to use checksums
3347eddc9509484589f79416ca1343e24ce74f060ad9224ef81488e782226900
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.9.18 Linux/5.15.133.1-microsoft-standard-WSL2

Release files / nurse-0.5.1-py3-none-any.whl

Download URL nurse-0.5.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff3f111b6c845510bbca1dc2ee26fce2c8d8df1182377823a72936fe392955da
BLAKE2b-256 checksum
How to use checksums
9eca97a5fa4eb5e1ea0789a66ec38c52b1414d2eaf0580de48156d257fdfc8cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.0 CPython/3.9.18 Linux/5.15.133.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page