Use SQLAlchemy with CherryPy
Project description
===================
CherryPy-SQLAlchemy
===================
.. image:: https://pypip.in/d/cp_sqlalchemy/badge.png
:target: https://pypi.python.org/pypi/cp_sqlalchemy
..
.. image:: https://badge.fury.io/py/cp_sqlalchemy.png
:target: http://badge.fury.io/py/cp_sqlalchemy
.. image:: https://travis-ci.org/ionrock/cp_sqlalchemy.png?branch=master
:target: https://travis-ci.org/ionrock/cp_sqlalchemy
CherryPy-SQLAlchemy makes it easy to use SQLAlchemy within CherryPy
apps.
Credits
=======
This package was primarily created from `Sylvain's SQLAlchemy
recipe
<http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html>`_.
Basic Usage
===========
There are two elements of CherryPy-SQLAlchemy
1. A CherryPy tool that will create a session for use with each
request.
2. A CherryPy plugin that can maintains information about the
database and binds the session to the specific DB.
Here is an example connecting to a sqlite db: ::
import cherrypy
from app import Root
from app.models import ORMBase
from cp_sqlalchemy import SQLAlchemyTool, SQLAlchemyPlugin
def run():
cherrypy.tools.db = SQLAlchemyTool()
cherrypy.tree.mount(Root(), '/', {
'/': {
'tools.db.on': True
}
})
SQLAlchemyPlugin(
cherrypy.engine, ORMBase, 'sqlite:////path/to/file.db'
)
cherrypy.engine.start()
cherrypy.engine.block()
One thin to note is the ORMBase we imported is
`sqlalchemy.ext.declarative.declarative_base()` that was used when
creating models.
From there, each request will have access to `cherrypy.request.db`,
which is an instance of a SQLAlchemy session.
There is a more complete `example.py` in the source.
* Free software: BSD license
..
* Documentation: https://cp_sqlalchemy.readthedocs.org.
CherryPy-SQLAlchemy
===================
.. image:: https://pypip.in/d/cp_sqlalchemy/badge.png
:target: https://pypi.python.org/pypi/cp_sqlalchemy
..
.. image:: https://badge.fury.io/py/cp_sqlalchemy.png
:target: http://badge.fury.io/py/cp_sqlalchemy
.. image:: https://travis-ci.org/ionrock/cp_sqlalchemy.png?branch=master
:target: https://travis-ci.org/ionrock/cp_sqlalchemy
CherryPy-SQLAlchemy makes it easy to use SQLAlchemy within CherryPy
apps.
Credits
=======
This package was primarily created from `Sylvain's SQLAlchemy
recipe
<http://www.defuze.org/archives/222-integrating-sqlalchemy-into-a-cherrypy-application.html>`_.
Basic Usage
===========
There are two elements of CherryPy-SQLAlchemy
1. A CherryPy tool that will create a session for use with each
request.
2. A CherryPy plugin that can maintains information about the
database and binds the session to the specific DB.
Here is an example connecting to a sqlite db: ::
import cherrypy
from app import Root
from app.models import ORMBase
from cp_sqlalchemy import SQLAlchemyTool, SQLAlchemyPlugin
def run():
cherrypy.tools.db = SQLAlchemyTool()
cherrypy.tree.mount(Root(), '/', {
'/': {
'tools.db.on': True
}
})
SQLAlchemyPlugin(
cherrypy.engine, ORMBase, 'sqlite:////path/to/file.db'
)
cherrypy.engine.start()
cherrypy.engine.block()
One thin to note is the ORMBase we imported is
`sqlalchemy.ext.declarative.declarative_base()` that was used when
creating models.
From there, each request will have access to `cherrypy.request.db`,
which is an instance of a SQLAlchemy session.
There is a more complete `example.py` in the source.
* Free software: BSD license
..
* Documentation: https://cp_sqlalchemy.readthedocs.org.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for CherryPy-SQLAlchemy-0.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4040dec0c5a16c95ec0fdceee1b03bca3b81d22320be32e38cbee4bfd485b542 |
|
MD5 | 093793b627496f8b0b6a327abb77577e |
|
BLAKE2b-256 | b24b0be8639e6a47ec1bcbdfdbf7ddc17fd0cf71dc859402daa7d859aa1bb278 |