Compiled router with trie-based path matching.
Routes are registered during setup and compiled into an immutable lookup structure when the app freezes.
routing.router
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
Return True if path uses<param> instead of \{param}.
Raise if path uses invalid<param> syntax. Chirp expects \{param}.
Parse a route path string into segments.
Examples::
"/users" -> [PathSegment("users")] "/users/{id}" -> [PathSegment("users"), PathSegment("{id}", is_param=True, ...)] "/users/{id:int}" -> [PathSegment("{id:int}", is_param=True, param_type="int")] "/files/{path:path}" ->…A node in the route trie. Mutable during compilation only.
A parameter edge in the trie.
A catch-all (path) edge — consumes remaining path.
Immutable path-scoped method metadata for protocol discovery.
Compiled router with trie-based path matching.
Usage::
router = Router()
router.add(Route("/users", handler, frozenset({"GET"})))
router.add(Route("/users/{id:int}", handler, frozenset({"GET"})))
router.compile()
match = router.match("GET", "/users/42")
_route_path_has_flask_syntax
function
def _route_path_has_flask_syntax(path: str) -> bool
Return True if path uses<param> instead of \{param}.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path
|
str
|
— |
validate_route_path
function
def validate_route_path(path: str) -> None
Raise if path uses invalid<param> syntax. Chirp expects \{param}.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path
|
str
|
— |
parse_path
function
def parse_path(path: str) -> list[PathSegment]
Parse a route path string into segments.
Examples::
"/users" -> [PathSegment("users")]
"/users/{id}" -> [PathSegment("users"), PathSegment("{id}", is_param=True, ...)]
"/users/{id:int}" -> [PathSegment("{id:int}", is_param=True, param_type="int")]
"/files/{path:path}" -> [PathSegment("{path:path}", is_param=True, param_type="path")]
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path
|
str
|
— |
_TrieNode
class
A node in the route trie. Mutable during compilation only.
_ParamEdge
class
A parameter edge in the trie.
_CatchAllEdge
class
A catch-all (path) edge — consumes remaining path.
_PathDiscovery
class
Immutable path-scoped method metadata for protocol discovery.
Router
class
Compiled router with trie-based path matching.
Usage::
router = Router()
router.add(Route("/users", handler, frozenset({"GET"})))
router.add(Route("/users/{id:int}", handler, frozenset({"GET"})))
router.compile()
match = router.match("GET", "/users/42")
View source · /home/runner/work/chirp/chirp/site/../src/chirp/routing/router.py:1