Skip to main content

Elixir plugin for cherrypy

Project description

CherrypyElixir is a cherrypy plugin that provides elixir functionalities on top of sqlalchemy , within cherrypy as a process bus plugin.

Example:

import cherrypy
import CherrypyElixir
from elixir import Entity, String, Field, OneToMany, Unicode, ManyToOne
CherrypyElixir.setup()


# define models
class Person(Entity):
    name = Field(String(128))
    addresses = OneToMany('Address')

class Address(Entity):
    email = Field(Unicode(128))
    owner = ManyToOne('Person')


class Root(object):

    @cherrypy.expose
    @cherrypy.tools.elixir()
    def index(self):
        yield '<ul>'
        for p in Person.query:
            yield '<li>'
            yield p.name
            yield ' '
            yield ','.join([a.email for a in p.addresses])
            yield '</li>'
        yield '</ul>'

    @cherrypy.expose
    @cherrypy.tools.elixir()
    def add(self,name=None,address=None):
        p = Person(name = name)
        for addr in address.split(','):
            p.addresses.append(Address(email=addr))

_cp_config={
    'global':{
        'server.socket_host'  : '0.0.0.0',
        'server.socket_port'  : 1919,
        'engine.elixir.on'    : True,
        'engine.elixir.echo'    : True,
        'engine.elixir.db_uri'    : 'sqlite://test.db'
    },
}

if __name__ == '__main__':
    cherrypy.quickstart(Root(), '', config=_cp_config)

To access sqlalchemy’s scoped_session directly , you can use cherrypy.request.db

Project details


Release history Release notifications

This version
History Node

0.5.1

History Node

0.5

History Node

0.4

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
CherrypyElixir-0.5.1-py2.7.egg (5.4 kB) Copy SHA256 hash SHA256 Egg 2.7 Dec 23, 2012
CherrypyElixir-0.5.1.tar.gz (3.2 kB) Copy SHA256 hash SHA256 Source None Dec 23, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page