Skip to main content

A dependency injection library for beginners

Project description

junkie

Junkie is a dependency injection library for beginners. It is easy to use and has no magic hidden state.

Core features:

  • injects instances via parameter name and if not available via type annotation
  • handles context managers when creating objects
  • provides simple configuration with dictionaries
  • can be easily combined with any other object instantiation approach
  • supports a flexible way to define scopes

Example:

from junkie import Context

class App:
    def __init__(self, text: str):
        self.text = text

    def greets(self) -> str:
        return self.text

context = Context({
    "greeting": "Hello",
    "name": "Joe",
    "text": lambda greeting, name: f"{greeting} {name}!"
})

with context.build(App) as app:
    assert app.greets() == "Hello Joe!"

Project details


Release history Release notifications

This version

1.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for junkie, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size junkie-1.0.0-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size junkie-1.0.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page