No project description provided
Project description
ditto: dependency injection tool
ditto is a simple and lightweight dependency injection tool for Python.
Features
- Easy-to-use decorators for dependency injection.
- Supports class and instance-based services.
- Sync and Async support
Installation
pip install pyditto
Usage
Declare your dependencies to ditto on application start.
import ditto as di
class Pokemon:
def attack(self) -> str:
pass
class FirePokemon(Pokemon):
def attack(self) -> str:
return 'Ember ! 🔥'
di.register(FirePokemon) # register as a class
di.register(FirePokemon()) # or as an object
Then you can inject your dependency into your class:
@di.inject
class Team:
charmander: FirePokemon
def battle(self):
self.charmander.attack()
team = Team()
team.battle() # 'Ember ! 🔥'
Or into an isolated function within your class:
class Team:
@di.inject
def battle(self, charmander: FirePokemon):
self.charmander.attack()
team = Team()
team.battle() # 'Ember ! 🔥'
Or just within a bare function:
@di.inject
def battle(charmander: FirePokemon):
self.charmander.attack()
battle() # 'Ember ! 🔥'
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyditto-0.1.2.tar.gz.
File metadata
- Download URL: pyditto-0.1.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/5.15.146.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecb877c19391846bdeb35412fce0e1995a900b22a9f22cba7d900a142b70a822
|
|
| MD5 |
dd04e2d28d9c1c60313d0bc0e0ea4529
|
|
| BLAKE2b-256 |
e87d9e0c65d3c9b317c9aa65e33f2092d1ba41a746c65ef372d0d8581493c410
|
File details
Details for the file pyditto-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyditto-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/5.15.146.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cc295d7a2b33192dfb6b4091b7c8a62727c62d0d6f5a4d929ff3cabdd92af8a
|
|
| MD5 |
8ae3285334c553f9e9d3738a00d979cd
|
|
| BLAKE2b-256 |
e0c39f834f0c11eebd263a04688ebbf98947221883f629df17a110836df8a570
|