Skip to main content

A thoughtful dependency injection framework 💉

Project description


  1. Overview

  2. Installation

  3. Usage

  4. License


Nurse is a dependency injection framework with a small API that uses type annotations to manage dependencies in your codebase.


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


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:

    def name(self) -> str:
        return "Leeroy Jenkins"

# Now, add it to nurse service catalog in order to use it later in your application

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:

class AngryAnimal(Animal):

    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.

class Game:
    player: Player
    enemy: Animal

    def welcome_hero(self):
        print(f"Welcome {} !")

    def summon_monster(self):

Game = Game()
# Welcome Leeroy Jenkins !
# Grrr! 🦁

Or in any function

def summon_monster(enemy: Animal):

# Grrr! 🦁

And it works with async function as well !

import asyncio

async def summon_monster(enemy: Animal):
# Grrr! 🦁

Finally, you can also retrieve a service without using a decorator

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


Nurse is released into the Public Domain. 🎉

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nurse-0.5.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

nurse-0.5.1-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page