Skip to main content

pyramid_basemodel - a thin, low level SQLAlchemy bindings to pyramid

Project description

pyramid_basemodel

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."""

    @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.

Tests

To run the tests use:

py.test -v --cov pyramid_basemodel tests/

[pyramid_basemodel]: http://github.com/fizyk/pyramid_basemodel [pyramid_simpleauth]: http://github.com/thruflo/pyramid_simpleauth [pyramid_tm]: http://pyramid_tm.readthedocs.org

Release

Install pipenv and –dev dependencies first, Then run:

pipenv run tbump [NEW_VERSION]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_basemodel-0.7.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyramid_basemodel-0.7.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file pyramid_basemodel-0.7.0.tar.gz.

File metadata

  • Download URL: pyramid_basemodel-0.7.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyramid_basemodel-0.7.0.tar.gz
Algorithm Hash digest
SHA256 333911cfe6ed8122a46b7810b5dea8abb1b411edb17d8f93976b73737c3388fb
MD5 24491e75c7649178a4830711ec5a2b3e
BLAKE2b-256 8a75aa17705aa6966cf0fdfd58811e97a005e70ecd8a1fa0513830d7d1b658e2

See more details on using hashes here.

File details

Details for the file pyramid_basemodel-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyramid_basemodel-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d95348cae2cc2482c3fdcfed0ee5c8250dffad5b19b20dd2fe99c1f81119d5ac
MD5 b2b1b105cf0e81f7ee8c2adb06474885
BLAKE2b-256 660649616d160da89bb4ea6061989ee19de7667f2d552280fbdefc600edb9c35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page