Skip to main content

Adds Injector support to Flask.

Project description

Adds Injector support to Flask.

Injector is a dependency-injection framework for Python, inspired by Guice.

Here’s a pseudo-example:

import sqlite3
from flask.ext.injector import Builder, route
from injector import inject

def bar():
    return render("bar.html")

# Route with injection
def foo(db):
    users = db.execute('SELECT * FROM users').all()
    return render("foo.html")

# Class-based view with injection
class Waz(object):
    def __init__(self, db):
        self.db = db

    def waz(self):
        users = db.execute('SELECT * FROM users').all()
        return 'waz'

def configure(binder):
    config = binder.injector.get(Config)

def main():
    views = [foo, bar, Waz]
    modules = [configure]
    app = Builder(views, modules, config={
        'DB_CONNECTION_STRING': ':memory:',

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 Flask-Injector, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size Flask-Injector-0.1.0.tar.gz (4.2 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