Skip to main content

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

Credits

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

Metadata

Release files for CherryPy-SQLAlchemy 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CherryPy-SQLAlchemy 0.5.3
File Size Uploaded
CherryPy-SQLAlchemy-0.5.3.tar.gz 3.3 kB Details

Release files / CherryPy-SQLAlchemy-0.5.3.tar.gz

Download URL CherryPy-SQLAlchemy-0.5.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b9704d4251994532e81014163427d3bc5eed66fce93a34432a827013e29b633c
BLAKE2b-256 checksum
How to use checksums
d9ce8d1b22e31daddab97d75fb980852cb275de9de7e2dbbc484ed47fdfae01d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.5.3 This release

1 release file

0.5.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page