Skip to main content

Modern Dependency Injection Container for Python 3.12+

Project description

Uncoupled

Tests

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


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.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uncoupled-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file uncoupled-0.1.1.tar.gz.

File metadata

  • Download URL: uncoupled-0.1.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.8

File hashes

Hashes for uncoupled-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d2c3b188c6a8166269741d041d13d72eb86908941e09bc8f5f4ddad38e6dfced
MD5 e98264c13428f7f70cc1596a00253040
BLAKE2b-256 a39db23aaf5a529526016945e9e15a039ed918e3e1cf6cb1effb489ecddf5c27

See more details on using hashes here.

File details

Details for the file uncoupled-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: uncoupled-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.8

File hashes

Hashes for uncoupled-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c301ec5616bf1c868c76492a05249ac5aa46cf1db37281fa70e7e92545acc41c
MD5 9825898fe192cba3c10974f4ae06d34f
BLAKE2b-256 f0810a04da28af4540479bf7d7d36e56db610e8bf2818e44af53c672771a8785

See more details on using hashes here.

Supported by

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