Skip to main content

A microframework

Project description

A microframework for Python 3, based on werkzeug.

https://img.shields.io/pypi/l/rouver.svg https://img.shields.io/github/release/srittau/rouver/all.svg https://img.shields.io/pypi/v/rouver.svg https://travis-ci.org/srittau/rouver.svg?branch=master

Routing

>>> from rouver.router import Router
>>> from rouver.response import respond_with_html, respond_with_json
>>> def get_index(environ, start_response):
...     return respond_with_html(start_response, "<div>Foo</div>")
>>> def get_count(environ, start_response):
...     return respond_with_json(start_response, {"count": 42})
>>> router = Router()
>>> router.add_routes([
...     ("", "GET", get_index),
...     ("count", "GET", get_count),
... ])

Routes with placeholders:

>>> def get_addition(environ, start_response):
...     num1, num2 = path
...     return response_with_json(start_response, {"result": num1 + num2})
>>> def numeric_arg(request, path, value):
...     return int(value)
>>> router.add_template_handler("numeric", numeric_arg)
>>> router.add_routes([
...     ("add/{numeric}/{numeric}", "GET", get_addition),
... ])

Routes with wildcards:

>>> def get_wildcard(environ, start_response):
...     # environ["rouver.wildcard_path"] contains the remaining path
...     return respond(start_response)
>>> router.add_routes([
...     ("wild/*", "GET", get_wildcard),
... ])

Sub-routers:

>>> def get_sub(environ, start_response):
...     return respond(start_response)
>>> sub_router = Router()
>>> sub_router.add_routes([
...     ("sub", "GET", get_sub),
... ])
>>> router.add_sub_router("parent", sub_router)

Argument Handling

>>> from rouver.args import Multiplicity, parse_args
>>> from rouver.response import respond_with_json
>>> def get_count_with_args(request, path, start_response):
...     args = parse_args(request.environ, [
...         ("count", int, Multiplicity.REQUIRED),
...     ])
...     return respond_with_json({"count": args["count"]})

WSGI Testing

>>> from rouver.test import create_request, test_wsgi_app
>>> request = create_request("GET", "/my/path")
>>> response = test_wsgi_app(app, request)
>>> response.assert_status(HTTPStatus.OK)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

rouver-0.10.5-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file rouver-0.10.5-py3-none-any.whl.

File metadata

  • Download URL: rouver-0.10.5-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6+

File hashes

Hashes for rouver-0.10.5-py3-none-any.whl
Algorithm Hash digest
SHA256 19224604b96bdecc82bb3abb55a3032a123934d6a8c7d1e6cc9bbc891b16b8b2
MD5 92e174d88e2f600c8523e3a7c1f2c899
BLAKE2b-256 3506a90faf11f64c681335c1e430af20ec068390a6ea24d4eb072506a7452f62

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page