Skip to main content

A microframework

Project description

Rouver

A microframework for Python 3, based on werkzeug.

MIT License PyPI - Python Version GitHub pypi Travis CI

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 Distribution

rouver-2.6.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

rouver-2.6.1-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file rouver-2.6.1.tar.gz.

File metadata

  • Download URL: rouver-2.6.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.7 Linux/5.19.0-35-generic

File hashes

Hashes for rouver-2.6.1.tar.gz
Algorithm Hash digest
SHA256 f5858f60ddb87b712b80339563a09acbc4d9076ddd09a1a44957831f458b4e2d
MD5 436fb7a41971404b8274b5375d9f62d2
BLAKE2b-256 1f6a0480bc0498f3dcad24d6a6d60295ec48ced9cee4f3cb6acf2dac8eb6b827

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rouver-2.6.1-py3-none-any.whl
  • Upload date:
  • Size: 39.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.7 Linux/5.19.0-35-generic

File hashes

Hashes for rouver-2.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf8dbf79b5bdd6f275eb2d93fc0208e0d7c4ad9bc9067925cdf8e2e2a0691731
MD5 a298a297fd665f760521c9266de3eb8b
BLAKE2b-256 046b585e5d6dff5649a2888e0859a7dd4fa326b7c840746d403d814b47e2a8e5

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