Skip to main content

Easy to use Dependency Injection Library

Project description

Easy-DI

Easy-DI is an easy to use Dependency Injection library.

Easy-DI allows you to implement the Dependency Injection pattern and manage the complexity of your Python applications.

Installing Easy-DI and Supported Versions

Easy-DI is available on PyPI:

$ python -m pip install easy-dependency-injection

Easy-DI officially supports Python 3.8+.

Key characteristics

  • Lightweight: the added overhead is comparable to accessing a module's constants
  • mypy-friendly: allows your IDE to infer the type of injected resources and help you with auto-complete and type hinting
  • Does one thing, does it well: it's just a dependency injection library.
  • Not invasive: you won't have to rewrite your application to use it; you can start taking advantage of the inversion of control gradually
  • Test-friendly: easy to integrate in your unit tests.

Known limitations

  • Only classes can be injected: no functions, no modules
  • Not tested with metaclasses
  • Performances decrease linearly with the number of injected resources

Example

from easy_di import DI, inject, injected


class Swallow:
    velocity: injected(str)

    def answer(self):
        return f"My airspeed velocity is {self.velocity}"

# this is needed only because the Swallow class is in the __main__ module,
# more realistic scenarios won't need the `inject` function call
inject(__name__)

if __name__ == "__main__":
    DI.register("velocity", "24 miles per hour")
    print(Swallow().answer())

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

easy-dependency-injection-0.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

easy_dependency_injection-0.2.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file easy-dependency-injection-0.2.0.tar.gz.

File metadata

File hashes

Hashes for easy-dependency-injection-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c6d03f63e90951e838612715c904ecab76e8bbb8f90567b9831095ed2d52ff79
MD5 85ef3f6a58afc93a7759ea5dd38e6a92
BLAKE2b-256 a2201a50868651abd4dc833342fe454a350012f9e5ae6b2d913a1e3068ba75b6

See more details on using hashes here.

File details

Details for the file easy_dependency_injection-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for easy_dependency_injection-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a12b2d64d384801126195bde6076b1fd3e062e2d572cf1d838024a1917c13cc
MD5 f4d27b6fd41ab2eab05f7916a5ccd74b
BLAKE2b-256 d67b9f4b193d945069d1000e52c604b62bc94ade5da444ac69ced9e4cb8b1273

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