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::

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/

CHANGES

0.5.1

  • [package] Marked python 3.10 compatible (Trove Classifiers)

0.5.0

  • [simplify] Removed inspect and to_slug from BaseSlugNameMixin.set_slug method. These parameters seemd like a way to override some core functionality, which seems like a rare enough case to not maintain it, especially without tests.
  • [simplify] Removed named_tempfile_cls from Blob.get_as_named_tempfile as it wasn't used.
  • [simplify] Simplified the Blob.update_from_url. Now the method accepts only url parameter and does exactly one thing.
  • [code] Use default arguments instead of compose sections.

0.4.0

  • [enhancement] Switch slugify to python-slugify as the latter is python3 compatible
  • [enhancement] As far as existing tests are concerned, now there's both full compatibility and feature parity between python 2 and python 3
  • [CI] use CI

0.3.7

Fix support for zope.sqlalchemy >= 1.2

0.3.4

Remove stray print statements.

0.3.3

Bump to remove src/*.egg-info directory from PyPI distribution.

0.3.2

Make engine kwargs configurable.

0.3.1

Introduce the basemodel.should_bind_engine config flag, which can be used, e.g.: in ftests, to disable the automatic engine setup, even when application code config.include('pyramid_basemodel')s.

Defaults to True!

0.3

Default basemodel.should_create_all to False. This will break apps that rely on tables being created by default. However, it's much saner to only invoke both metadata.create_all(engine) and metadata.drop_all(engine) when explicitly told to, particularly as most applications will use migrations to manage the database schema.

0.2.4 -> 0.2.6

Faff about horribly with the slug generation code.

0.2.3

Fix Python3 KeyError syntax bug.

0.2.2

Support dotted path sqlalchemy.pool_class configuration.

0.2.1

Provide util.get_object_id function and stamp sqlalchemy.ext.declarative.declarative_base() subclasses with the interfaces.IDeclarativeBase interface.

0.2

Fix Python3 support (requires 3.3 for the unicode literal character).

0.1.8

Allow concrete subclasses of BaseModelContainer to be provided in the tree.BaseContentRoot.mapping (as well as interfaces).

0.1.7

Added a pyramid_basemodel.blob.Blob model class to store large binary files.

Fixed up .slug module doctests. Fix ``install_requireslist insetup.py`.

0.1.6

Base the BaseMixin.class_name on a singularised version of the plural class name. This may seem a bit arse about face, but allows us to use the tablename to split the word, e.g.:

>>> class OperatingScale(Base, BaseMixin):
...     __tablename__ 'operating_scales'
... 

>>> OperatingScale.class_name
'Operating Scale'

Just ignore all this if you don't plan on using the class_name, class_slug and plural_class_name properties.

0.1.5

Provide BaseMixin.class_slug and base it and the BaseMixin.plural_class_name on the cls.__tablename__ instead of the cls.__name__.

All still manually overrideable by providing the corresponding property with a single underscore, e.g.: cls._plural_class_name.

0.1.4

Provide BaseMixin.class_name and BaseMixin.plural_class_name.

0.1.3

Bugfix to parse config options properly.

0.1.2

Added basemodel.should_create_all configuration option.

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

Uploaded Source

Built Distribution

pyramid_basemodel-0.5.1-py2.py3-none-any.whl (15.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: pyramid_basemodel-0.5.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pyramid_basemodel-0.5.1.tar.gz
Algorithm Hash digest
SHA256 b93bef0d821e3c0907b056e42b65ea4f08570a8898e4df16028666e870a3a9d2
MD5 47c396bfaed3912f90f8ad434929a3ad
BLAKE2b-256 22ce27817c457993088509443ab1706571eb0ca8ae9f69018bda264abda72110

See more details on using hashes here.

File details

Details for the file pyramid_basemodel-0.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pyramid_basemodel-0.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for pyramid_basemodel-0.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 371c1f6911405faf25df673b7cb9b8d1d4b38a5e5aa053719773c928f75a5e9a
MD5 dff332b68aae4b93d824bea53b476150
BLAKE2b-256 14e0f4cecde225b53084949fa179c592932751ffe83ab9bd88815a3305ff279b

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