A thoughtful dependency injection framework 💉
Project description
Outline
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 .. 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.
import nurse
# A user defined class that will be used accross your application
class SSHClient:
def user(self) -> str:
return "John Doe"
# Now, add it to nurse service catalog in order to use it later in your application
nurse.serve(SSHClient())
Once you filled-in the service catalog with your different component, your can declare them as dependencies to any of your class.
import nurse
@nurse.inject
class Server:
ssh_client: SSHClient
def response(self) -> str:
return f"Hello {self.ssh_client.user()} !"
server = Server()
server.response()
# Hello John Doe !
License
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.2.1.tar.gz
(2.6 kB
view hashes)
Built Distribution
nurse-0.2.1-py3-none-any.whl
(3.9 kB
view hashes)