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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyramid_basemodel-0.6.0.tar.gz
.
File metadata
- Download URL: pyramid_basemodel-0.6.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a4c4d0511cc72a361cc17bf3e0a8481b952682a2e9ec5a7e11048a0769ffdbd |
|
MD5 | f829eef054e4fc2801d7c3ca6e8c03fd |
|
BLAKE2b-256 | 9e65aa7e0b4eb1889bb18ee593df339e07dbfb1b0d2f5d031778a2208910550e |
File details
Details for the file pyramid_basemodel-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: pyramid_basemodel-0.6.0-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9ae341838fc2179a800e95c9e1bcee1fba9cb08f5d3d358c8248a136e037a9 |
|
MD5 | 8499c82aa0ad55b752468251357d1bb9 |
|
BLAKE2b-256 | 35238f6e5b6bddf54e7f581751e0e7a4dbd0c320ac66c1cb2762e1446082ee35 |