Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A Very Simple Python Dependency Injector

Project description


Build Status

A Very Simple Python Dependency Injector


Use pip!

pip install pychkari


Pychkari (pronounced peach kaa ree) is a simple dependency injector for Python. It is intended to be a no-fuss library that depends on as few packages as possible and just works.

This example should get us started!

# Class definitions for reference

class A:
    def __init__(self, 
                 depOne,                    # casing support
                 second_dep: "DepTwo",      # annotations support
                 const_dep=3):              # not a dependency
        self.dep1 = depOne
        self.dep2 = second_dep
        self.const_d = const_dep

class DepOne:
    def __init__(self):
        self.timestamp =

class DepTwo:
    def __init__(self):
        self.timestamp =

class B:
    def __init__(self, a, dep_one):
        self.a = a
        self.dep1 = dep_one

# registration

container = Container.instance()
container.register("MyAwesomeService", B)   # explicitly named registration
container.register_class(A)                 # service name "A" implicit
container.register_class(DepOne)            # service name "DepOne" implicit
container.register_class(DepTwo)            # service name "DepTwo" implicit

# instantiation

service = container.get("MyAwesomeService") # creates instance of "B" with dependencies injected



Pychkari is barely a few kilobytes. It doesn't have third party dependencies. Just drop it into your project and run with it.

Zero Commitment

Pychkari doesn't require you to change your code. As long as common Python conventions are followed, your existing code just works!
No fancy annotations, no decorations, no commitments. You're free to mix and match with any other framework.

This chart should tell you how dependencies are resolved:

Dependency Resolved Service Name
underscore_case UnderscoreCase
camelCase CamelCase
PascalCase PascalCase
my_Weird_case MyWeirdCase
my_service:HttpClient HttpClient


Well, sort of! If the conventions don't satisfy your complex naming schemes, you can always make the names explicit by annotating the dependencies.
For example, client:"MyService" will inject and instance of MyService in place of client.

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 pychkari, version 1.1.2
Filename, size File type Python version Upload date Hashes
Filename, size pychkari-1.1.2-py3-none-any.whl (17.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pychkari-1.1.2.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

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