Skip to main content

Dependency injection for python

Project description


Dependency Injection for Python


Gluer uses type annotations, so python 3.6+ is required

python3 -m pip install --user gluer


Let's follow a wonderful explanation of DI:

from abc import ABC, abstractmethod
from gluer import Gluer

class Drink(ABC): # this doesn't *have* to be abstract
	def sip(self):

class Child:
	def __init__(self, drink: Drink):
		self.drink = drink

	def take_a_sip(self):

class Juice(Drink):
	def sip(self):

class Coke(Drink):
	def sip(self):

if __name__ == "__main__":
	gluer = Gluer()
	mom_watches = True

	gluer.register(Juice if mom_watches else Coke).As(Drink)

	container =

	kid = container.resolve(Child)
	kid.take_a_sip() # *gulp* ahhh

Project details

Download files

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

Files for gluer, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size gluer-0.2.0.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page