Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Simple Dependency Injection for python

Project Description

CNS Dependency Injection is a very simple way to store and inject services into your software.

It looks like this for Flask (dumb example, but you should get the point):

from di.helpers import get_service, add_service
from di.decorator import service, inject
from flask import Flask

app = Flask(__name__)
add_service('router', app.route)

def adder(*args):
  sum = 0
  for arg in args:
    sum += arg
  return sum

router = get_service('router')

def adds():
  sum = get_service('adder')([1,2,3])
  return "hello " + repr(sum)


If you are going to @inject into a class, do it on the __init__ function. @service can be used with classes or functions.

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
CNSdi-0.1.4.tar.gz (5.8 kB) Copy SHA256 Checksum SHA256 Source Sep 21, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting