Skip to main content

A microframework

Project description

Rouver

A microframework for Python 3, based on werkzeug.

Supported Python Versions] GitHub pypi MIT License GitHub Workflow Status

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rouver-2.7.0-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rouver-2.7.0.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-88-generic

File hashes

Hashes for rouver-2.7.0.tar.gz
Algorithm Hash digest
SHA256 6acdee28d195085a9a6bb06fe0d2a0318037d6ffc36d24c3b5ab1420b417c29b
MD5 0af5e5f3fbe9574b8abd8e400c1ab58f
BLAKE2b-256 7f6629c60c2835b2ea131cc94e35a617b63d4d1ce2a030acdda64a18ea35ffc5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rouver-2.7.0-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-88-generic

File hashes

Hashes for rouver-2.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5c6e92fe41907b8e8d5b0f3de2cba15321ac15071a049b689c5218647b617ec
MD5 62077a5f09662eab7f1e0b94c11f6eff
BLAKE2b-256 5127e65bbebe52cf93b88c30cdd283d831956e01aca0602a9aea2f01c1b0d5f3

See more details on using hashes here.

Supported by

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