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
A CherryPy tool that will create a session for use with each request.
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cp_sqlalchemy-0.5.1.tar.gz.
File metadata
- Download URL: cp_sqlalchemy-0.5.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
894f0de45202d0981cf0647c73fe5e07e6b7fcf484ad972a8e4a506a7a39e810
|
|
| MD5 |
bc1c1ac037164c73a51c146c5348762a
|
|
| BLAKE2b-256 |
108bf60653db3743821661cc208170c57c409c97600e918c093d24cd45baad11
|