Modern Dependency Injection Container for Python 3.12+
Project description
Uncoupled
Modern Dependency Injection Container for Python 3.12+
Usage
from typing import Protocol
from uncoupled.container import Container, Depends
# Define the protocol (i.e the interface)
class IService(Protocol):
def compute(self) -> int: ...
# Define a concrete implementation of the protocol
class ServiceImpl(IService):
def compute(self) -> int:
return 42
# Inject with `Depends` the required protocol
def my_function(svc: IService = Depends(IService)) -> None:
print(svc.compute()) # Should return 42 !
if __name__ == "__main__":
# Create a container and map a protocol to an implementation with a specific lifetime
Container.create().add_transient(IService, ServiceImpl)
# Call the function without arguments, `Depends` will take care of the injection
my_function()
Have a look at the
example
folder for more examples !
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
uncoupled-0.1.0.tar.gz
(11.2 kB
view details)
Built Distribution
File details
Details for the file uncoupled-0.1.0.tar.gz
.
File metadata
- Download URL: uncoupled-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e9b802b7e3ccc90276ca6dbb721f0dc7d570e62b45c90b4dfc6cc0fd4453b41 |
|
MD5 | e49a029148b1623c16ad806e3124c823 |
|
BLAKE2b-256 | ba3e96d907ef5b63ec0fbea17e845a083b02e9b439b3f38bc74a98e90d8ed74f |
File details
Details for the file uncoupled-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: uncoupled-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6678e7eb1c620359e1827ef9d4c9a6a1d75e260cead3f4b9886a77673f7de753 |
|
MD5 | f4986ee88483d3ddce18adce9ccd0b6e |
|
BLAKE2b-256 | 1a7c010f5a52a047f01d26ee1da8ae1fd6e070856172c56bb2f74729477c7dc6 |