https://github.com/srittau/rouver
Python 3 microframework
https://github.com/srittau/rouver
microframework python python3 wsgi
Last synced: 5 months ago
JSON representation
Python 3 microframework
- Host: GitHub
- URL: https://github.com/srittau/rouver
- Owner: srittau
- License: mit
- Created: 2017-10-19T04:04:40.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-06-16T11:01:54.000Z (about 1 year ago)
- Last Synced: 2025-06-19T05:02:45.360Z (about 1 year ago)
- Topics: microframework, python, python3, wsgi
- Language: Python
- Size: 862 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Rouver
A microframework for Python 3, based on werkzeug.

[](https://github.com/srittau/rouver/releases/)
[](https://pypi.python.org/pypi/rouver/)
[](https://github.com/srittau/rouver/blob/main/LICENSE)
[](https://github.com/srittau/rouver/actions/workflows/test-and-lint.yml)
## Routing
```python
>>> 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, "
Foo")
>>> 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:
```python
>>> 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:
```python
>>> 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:
```python
>>> 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
```python
>>> 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
```python
>>> 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)
```