Skip to main content
sqlalchemy_traversal
====================

This is a pyramid extension that allows you to use traversal with SQLAlchemy objects

Demo App here: https://github.com/eventray/sqlalchemy_traversal_demo

To use this you just have to include sqlalchemy_traversal in your pyramid application
by either putting it in your development.ini:

pyramid.includes =
sqlalchemy_traversal

or by including it in your main:

config.include('sqlalchemy_traversal')


Then you just register your SQLAlchemy session and declarative base:

from sqlalchemy_traversal.interfaces import ISASession
from sqlalchemy_traversal.interfaces import ISABase

config.registry.registerUtility(DBSession, ISASession)
config.registry.registerUtility(Base, ISABase)


And then place the TraversalMixin on any SQLAlchemy class and it will automatically
be traversed:

from sqlalchemy_traversal import TraversalMixin


class User(TraversalMixin, Base):
pass


Now you will be able to hit the URL /traverse/user to get all the users in your database


You can also tell it to load relationships via the _json_eager_load property:

class User(TraversalMixin, Base):
_json_eager_load = ['permissions']


Saving
==================================
If you want to be able to create data with your API but the content
coming back doesn't exactly match your model or you want to run it through
schema validation first you can use the register save decorator:

@register_save(MyModel, MySchema):
def saving_my_model(request, data):
data['my_prop'] = 'NEW DATA'
return data

You can also handle data exceptions with exception_handlers:

def handle_integrity_error(model, exception):
return {
'errors': {
'message': 'That data is not unique'
}
}

@register_save(
MyModel
, MySchema
, exception_handlers={
IntegrityError: handle_integrity_error
}
):
def saving_my_model(request, data):
data['my_prop'] = 'NEW DATA'
return data

Metadata

Release files for sqlalchemy_traversal 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy_traversal 0.5.2
File Size Uploaded
sqlalchemy_traversal-0.5.2.tar.gz 11.5 kB Details

Release files / sqlalchemy_traversal-0.5.2.tar.gz

Download URL sqlalchemy_traversal-0.5.2.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
45ab3775ef2154ab7f0b52ff001e2efa9e42a13478bb9f3273d18807d8c2add6
BLAKE2b-256 checksum
How to use checksums
0346d99eaab53d24c91cadc1c05667d13fd3ffb3652c008b10a6aafeb0a1abe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.2 This release

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4

1 release file

0.2

1 release file

0.1

1 release file

0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page