Radish is a simple router implementation for my web framework, Ermine. However, it can also be used for other things, and provides complete typing. It does use an regex tree for routing.
- simple
- elegant
- comprehensiv
pip install radish-router
Radish is inspired by:
- simple matching
- dynamic routes
- parameters
- wildcards
- regex
Basic static route matching
from radish import Radish
router = Radish()
handler = lambda: "Hello World!"
router.insert("get", "/hello/world", handler)
print(router.get("get", "/hello/world"))
# will return
# {"route": "/user","handler": handler, "params": {}}Route parameters
from radish import Radish
route = Radish()
handler = lambda: "Hello World!"
router.insert("get", "/hello/:name", handler)
router.insert("get", "/user/:uid|uuid", handler)
router.insert("get", "/static/*filename", handler)
print(router.get("get", "/user/16e55f79-baa7-46ed-b9a8-8dabc35c6381"))
print(router.get("get", "/hello/world"))