Skip to main content

Middleware for use Storm ORM in WSGI applications

Project description

Introduction

Storm is a fast, small and powerful object-relational mapper. Try it to use in web-aware applications.

WSGI application mainly miltithreaded, but Store object is not thread safe.

Middlestorm middleware adds a thread safe Store object instance in environ dictonary. Each thread have self Store.

Simple example

There are 2 ways to create middleware:
  • class

  • decorator

Class middleware:

from wsgiref.simple_server import make_server
from storm.database import create_database

from middlestorm import MiddleStorm

def storm_app(environ, start_response):
    store = environ['storm.store']
    # ...

db = create_database('postgres://user:password@host/base')
app = MiddleStorm(storm_app, db)

make_server('', 8000, app).serve_forever()

Decorator middleware:

from wsgiref.simple_server import make_server
from storm.database import create_database

import middlestorm

@middlestorm.decorator(create_database('postgres://user:password@host/base'))
def storm_app(environ, start_response):
    store = environ['storm.store']
    # ...

make_server('', 8000, storm_app).serve_forever()

By default Store placed in in variable storm.store. This can be customized:

app = MiddleStorm(storm_app, db, key='custom.mystore')

or decorator style:

@middlestorm.decorator(db, key='custom.mystore')
def storm_app(environ, start_response):
    store = environ['custom.mystore']

Project details


Download files

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

Source Distribution

middlestorm-0.6.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

middlestorm-0.6-py2.5.egg (4.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page