Skip to main content

SQLAlchemy integration for Bottle.

Project description

This bottle-sqlalchemy plugin integrates SQLAlchemy with your Bottle
application. It injects a SQLAlchemy session in your route and handle the session cycle.

Usage Example:

import bottle
from bottle import HTTPError
from bottle.ext import sqlalchemy
from sqlalchemy import create_engine, Column, Integer, Sequence, String
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
engine = create_engine('sqlite:///:memory:', echo=True)

app = bottle.Bottle()
plugin = sqlalchemy.Plugin(engine, Base.metadata, create=True)

class Entity(Base):
__tablename__ = 'entity'
id = Column(Integer, Sequence('id_seq'), primary_key=True)
name = Column(String(50))

def __init__(self, name): = name

def __repr__(self):
return "<Entity('%d', '%s')>" % (,

def show(name, db):
entity = db.query(Entity).filter_by(name=name).first()
if entity:
return {'id':, 'name':}
return HTTPError(404, 'Entity not found.')

def put_name(name, db):
entity = Entity(name)

@app.get('/spam/:eggs', sqlalchemy=dict(use_kwargs=True))
def route_with_view(eggs, db):
# do something useful here

It is up to you create engine and metadata, because SQLAlchemy has
a lot of options to do it. The plugin just handle the SQLAlchemy

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 bottle-sqlalchemy, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size bottle-sqlalchemy-0.3.tar.gz (4.2 kB) File type Source Python version None Upload date Hashes View

Supported by

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