Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Resource baseclasses for traversal in Pyramid

Project description

Kalpa provides a starting point for resource traversal in Pyramid. It provides two classes for this, a Branch and a Leaf, which allow you to create arbitrary resource trees without the boilerplate.

There is also a Root class for added convenience that accepts a request during initialization. This can be used to create a starting point for Pyramid’s traversal.

from kalpa import Root, Node, branch

USERS = {...}


class Root(Root):
    """Root resource for Pyramid traversal."""
    users = branch('UserCollection')


class UserCollection(Node):
    """User collection, for listings, or loading single users."""
    __child_cls__ = 'User'

    def __load__(self, key):
        """Returns dict with attributes to create a child node from."""
        return {'user': USERS[key]}  # Load user or raise KeyError.


class User(Node):
    """User resource, a single loaded user."""
    gallery = branch('UserGallery', aliases=['images'])


class UserGallery(Node):
    """Gallery of images posted by a user.

    Reachable as `/users/:id/gallery` but also `/users/:id/images`.
    """

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
kalpa-0.5.0.tar.gz (10.3 kB) Copy SHA256 hash SHA256 Source None Sep 20, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page