Skip to content

nripankadas07/urltemplate

urltemplate

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.

Install

From a repository checkout:

python -m pip install -e .

Quick Start

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"

API

  • 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) and encode_reserved(value) expose the two RFC encoding modes used by operators.
  • URITemplateError, TemplateSyntaxError, and ExpansionError separate syntax failures from expansion-time value failures.

Scope

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.

Development

python -m pip install -e ".[dev]"
pytest

License

MIT - see LICENSE.

About

Zero-dependency RFC 6570 URI Template expansion (levels 1-3).

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages