Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Global base classes for Pyramid SQLAlchemy applications.

Project description

[pyramid_basemodel][] is a thin, low level package that provides an SQLAlchemy
declarative `Base` and a thread local scoped `Session` that can be used by
different packages whilst only needing to be bound to a db engine once.

# Usage

You can use these as base classes for declarative model definitions, e.g.::

from pyramid_basemodel import Base, BaseMixin, Session, save

class MyModel(Base, BaseMixin):
"""Example model class."""

def do_foo(cls):
instance = Session.query(cls).first()

You can then bind these to the `sqlalchemy.url` in your paster `.ini` config by
importing your model and this package, e.g.:

# for example in
import mymodel

def main(global_config, **settings):
config = Configurator(settings=settings)
return config.make_wsgi_app()

Or if this is all too much voodoo, you can just use the `bind_engine` function::

from pyramid_basemodel import bind_engine
from mypackage import mymodel

# assuming `engine` is a bound SQLAlchemy engine.

Note that the `Session` is designed to be used in tandem with [pyramid_tm][].
If you don't include `pyramid_tm`, you'll need to take care of committing
transactions yourself.

# Tests

To run the tests use, e.g.:

nosetests --cover-package=pyramid_base_model --cover-tests --with-doctest --with-coverage pyramid_basemodel
Name Stmts Miss Cover Missing
src/pyramid_basemodel/__init__ 32 0 100%
Ran 4 tests in 0.031s



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 pyramid-basemodel, version 0.3.5
Filename, size File type Python version Upload date Hashes
Filename, size pyramid_basemodel-0.3.5.tar.gz (13.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page