Giter Club home page Giter Club logo

traversalkit's Introduction

TraversalKit

The library provides tools to build resource tree for applications that use traversal routing. It has been developed to be used with Pyramid web application framework, however it does not depend on it and can be used within any application.

It helps implement resource tree hierarchy in a simple declarative way:

>>> from traversalkit import Resource, DEC_ID

>>> class Root(Resource):
...     """ Tree root """

>>> @Root.mount('users')
... class Users(Resource):
...     """ Users collection """

>>> @Users.mount_set(DEC_ID, metaname='user_id')
... class User(Resource):
...     """ User resource """

>>> @Root.mount('posts')
... @User.mount('posts')
... class Posts(Resource):
...     """ Posts collection """

>>> @Posts.mount_set(DEC_ID, metaname='post_id')
... class Post(Resource):
...     """ Post resource """

>>> for route in Root.routes():
...     print(route)
<Route: />
<Route: /posts/>
<Route: /posts/{post_id}/>
<Route: /users/>
<Route: /users/{user_id}/>
<Route: /users/{user_id}/posts/>
<Route: /users/{user_id}/posts/{post_id}/>

These resources comply Pyramid traversal interface and Pyramid location awareness interface.

>>> root = Root()
>>> user = root['users']['1']
>>> user
<User: /users/1/>
>>> user.__name__
'1'
>>> user.__parent__
<Users: /users/>
>>> user['posts']
<Posts: /users/1/posts/>
>>> user['documents']  # DOCTEST: +ellipsis
Traceback (most recent call last):
...
KeyError: ('documents', '/users/1/')

Links

traversalkit's People

Contributors

kr41 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.