Skip to main content

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, Branch, Leaf

USERS = {...}

class UserCollection(Branch):
    """User collection, for listings, or loading single users."""

    def __load__(self, key):
        """Return child resource with requested user included."""
        user = USERS[key]  # Load user or raise KeyError.
        return self._child(key, user=user)

class User(Branch):
    """User resource, a single loaded user."""

@User.attach('gallery', aliases=['images'])
class UserGallery(Leaf):
    """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.

Files for kalpa, version 0.4
Filename, size File type Python version Upload date Hashes
Filename, size kalpa-0.4-py2.py3-none-any.whl (9.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size kalpa-0.4.tar.gz (7.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page