Metadata-Version: 2.4
Name: pyramid-basemodel
Version: 1.0.0
Summary: pyramid_basemodel - a thin, low level SQLAlchemy bindings to pyramid
Keywords: pyramid,sqlalchemy
Author: James Arthur
License-Expression: Unlicense
License-File: UNLICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Pyramid
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: inflect
Requires-Dist: pyramid
Requires-Dist: pyramid-tm
Requires-Dist: python-slugify
Requires-Dist: requests
Requires-Dist: sqlalchemy>=2
Requires-Dist: zope-interface
Requires-Dist: zope-sqlalchemy
Maintainer: Grzegorz Śliwiński
Maintainer-email: Grzegorz Śliwiński <fizyk+pypi@fizyk.dev>
Requires-Python: >=3.10
Project-URL: Source, https://github.com/fizyk/pyramid_basemodel/
Project-URL: Bug Tracker, https://github.com/fizyk/pyramid_basemodel/issues
Project-URL: Changelog, https://github.com/fizyk/pyramid_basemodel/blob/v1.0.0/CHANGES.rst
Description-Content-Type: text/x-rst

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

.. code-block:: python

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

.. code-block:: python

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

.. code-block::

    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
