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.5.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

rouver-2.5.1-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rouver-2.5.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.2 Linux/5.10.0-20-amd64

File hashes

Hashes for rouver-2.5.1.tar.gz
Algorithm Hash digest
SHA256 381d05c4ce0429a1e75c8b94f459531d5b8d65547c65fa5d330a4333f2c10567
MD5 9ff822a924ad67e491fe547379c59320
BLAKE2b-256 36771e2f90a206f38c95c1ede71994f9298b08ba924100c0779f074876f43927

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rouver-2.5.1-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.9.2 Linux/5.10.0-20-amd64

File hashes

Hashes for rouver-2.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 221cc1e76c6062110d4185969b5aa2c6d3f0c30e3f98fd8a212985803fd302b3
MD5 0eaee54661669b7430ca346989b1d2d7
BLAKE2b-256 e7a08dea738ca549b19221227883b8a5ad772eb012bd73a75074297bc49de1dc

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