pyramid_basemodel - a thin, low level SQLAlchemy bindings to pyramid
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.
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.""" @classmethod def do_foo(cls): instance = Session.query(cls).first() save(instance)
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 yourapp.__init__.py import mymodel def main(global_config, **settings): config = Configurator(settings=settings) config.include('pyramid_basemodel') config.include('pyramid_tm') return config.make_wsgi_app()
Or if this is all too much voodoo, you can just use the bind_engine function:
.. code-block:: python
from pyramid_basemodel import bind_engine from mypackage import mymodel
# assuming engine is a bound SQLAlchemy engine. bind_engine(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.
To run the tests use:
py.test -v --cov pyramid_basemodel tests/
Install pipenv and –dev dependencies first, Then run:
pipenv run tbump [NEW_VERSION]
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for pyramid_basemodel-0.6.1-py3-none-any.whl