https://github.com/sontek/tomb_routes
Simple utility library around pyramid routing
https://github.com/sontek/tomb_routes
Last synced: about 2 months ago
JSON representation
Simple utility library around pyramid routing
- Host: GitHub
- URL: https://github.com/sontek/tomb_routes
- Owner: sontek
- Fork: true (TombProject/tomb_routes)
- Created: 2015-01-15T18:56:31.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-24T15:37:56.000Z (over 10 years ago)
- Last Synced: 2025-10-28T00:35:23.699Z (3 months ago)
- Language: Python
- Size: 120 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: ChangeLog
Awesome Lists containing this project
- awesome-pyramid - tomb_routes - Simple utility library (Other)
README
tomb_routes
=================================
.. image:: https://img.shields.io/pypi/v/tomb_routes.svg
:target: https://pypi.python.org/pypi/tomb_routes
.. image:: https://img.shields.io/travis/tomborine/tomb_routes.svg
:target: https://travis-ci.org/tomborine/tomb_routes
Intro
=================================
A set of simple defaults for Pyramid_ routing.
Pyramid's `URL dispatch`_ has separate concepts for **routes** and **views**.
This gives additional flexibility in that you can one route map to multiple
views, using different predicates (e.g.: predicates depending on `Accept`
header, whether request is XHR or not, etc.). In many applications, this
flexibility is not needed and having both **routes** and **views** adds a bit
of complexity and duplication, and reduces DRYness. This module implements some
easy-to-use mechanisms that create a route and a view in one step, resulting in
simpler, easier to understand code. This kind of makes Pyramid's routing look a
bit more like Flask_, albeit without Flask's controversial `thread locals`_.
You can use ``simple_route`` as a decorator:
.. code-block:: python
from tomb_routes import simple_route
from pyramid.response import Response
@simple_route('/hello/{name}')
def my_route(request, name):
return Response('Hello %s' % name)
or you can use it from the configurator:
.. code-block:: python
config.include('tomb_routes')
config.add_simple_route(
'/hello/{name}', view_callable,
renderer='json'
)
Inspirations
=========================
Frameworks with very simple routing (including so-called "microframeworks") are
nothing new. Here are a few in the Python world:
- minion_
- Klein_
- Flask_
Pyramid is a very powerful and extensible web framework and it's a framework
that we love, but sometimes we want very simple routing. This package brings
the simplified routing from microframeworks to Pyramid, so we can have our cake
and eat it too.
.. _Pyramid: http://www.trypyramid.com/
.. _URL dispatch: http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/urldispatch.html
.. _minion: https://pypi.python.org/pypi/minion
.. _Klein: https://github.com/Twisted/Klein
.. _Flask: http://flask.pocoo.org/
.. _thread locals: http://flask.pocoo.org/docs/latest/design/#thread-locals