Skip to main content

Use SQLAlchemy with CherryPy

Project description


.. image::

.. image::

.. image::

CherryPy-SQLAlchemy makes it easy to use SQLAlchemy within CherryPy


This package was primarily created from `Sylvain's SQLAlchemy

Basic Usage

There are two elements of CherryPy-SQLAlchemy

1. A CherryPy tool that will create a session for use with each
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(): = SQLAlchemyTool()
cherrypy.tree.mount(Root(), '/', {
'/': {
'tools.db.on': True

cherrypy.engine, ORMBase, 'sqlite:////path/to/file.db'


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 `` in the source.

* Free software: BSD license
* Documentation:

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 CherryPy-SQLAlchemy, version 0.5.2
Filename, size File type Python version Upload date Hashes
Filename, size CherryPy-SQLAlchemy-0.5.2.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page