Zero-dependency RFC 6570 URI Template expansion for Python, focused on levels 1-3: simple variables, reserved expansion, fragments, labels, path segments, query parameters, and continuation operators.
From a repository checkout:
python -m pip install -e .from urltemplate import URITemplate, expand
expand("/users/{id}", {"id": "alice@example.com"})
# "/users/alice%40example.com"
expand("/search{?q,limit}", {"q": "uri templates", "limit": 10})
# "/search?q=uri%20templates&limit=10"
template = URITemplate("/repos/{owner}/{repo}{?tab}")
template.variables # ("owner", "repo", "tab")
template.expand({"owner": "nripankadas07", "repo": "urltemplate"})
# "/repos/nripankadas07/urltemplate"expand(template, variables=None)parses and expands in one call.parse(template)returns parsed literal/expression components.URITemplate(template)caches parsed components for repeated expansion.encode_unreserved(value)andencode_reserved(value)expose the two RFC encoding modes used by operators.URITemplateError,TemplateSyntaxError, andExpansionErrorseparate syntax failures from expansion-time value failures.
This library targets RFC 6570 levels 1-3. Level-4 explode (*) and prefix
(:n) modifiers are intentionally rejected with explicit syntax errors. It is
not intended to be a URL router, validator, or HTTP client.
python -m pip install -e ".[dev]"
pytestMIT - see LICENSE.