Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Use SQLAlchemy with CherryPy

Project Description

CherryPy-SQLAlchemy makes it easy to use SQLAlchemy within CherryPy apps.


This package was primarily created from Sylvain’s SQLAlchemy recipe.

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(): = 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.

Release History

Release History

This version
History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
cp_sqlalchemy-0.5.1.tar.gz (3.4 kB) Copy SHA256 Checksum SHA256 Source Jan 12, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting