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.6.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyramid_basemodel-0.6.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pyramid_basemodel-0.6.1.tar.gz
Algorithm Hash digest
SHA256 108c235ea642e49c52181548cccae13160fb977811b0cdac99aa03ccbe7bf591
MD5 f5c7033288676821c87ffb54e6d51058
BLAKE2b-256 f4be744216b59b2afcb58be66d4ad1b1c00a268745d498af2a23040a12d72ef1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyramid_basemodel-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04804e313f62d391d39d93bba2068beae9d5ca6bf20d4a692fee737c9ebbf485
MD5 fcf20dd527ded0e1b9de63b04eb27756
BLAKE2b-256 b53a96b879acc8b3048617d6cb20decbb81f011a04ce6acb76cca61210138ca1

See more details on using hashes here.

Supported by

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