The `uri-template` library provides an implementation of RFC 6570 URI Templates in Python. It supports template expansion in strict adherence to the RFC, while also introducing several extensions for handling non-string values, nested structures, and partial expansions. The current version is 1.3.0, released in June 2023. It appears to be maintained with a slower release cadence by a single maintainer.
pip install uri-templateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic URI template expansion using both the standalone `expand` function and the `URITemplate` class. It also shows how to perform partial template expansions.
Verify which package is required for your project. If you intend to use the `uritemplate` (no hyphen) package, install `pip install uritemplate` and import `from uritemplate import ...`.
Refer to the library's documentation on 'RFC 6570 Extensions' to understand how different Python types are handled during expansion, especially for nested structures or non-standard primitive types.
Avoid using prefix modifiers with composite values or handle the `ExpansionFailed` exception in your code. Ensure that the types of values passed to template variables are compatible with the specified modifiers.
If default values are needed for non-string types, you must provide them programmatically before calling the `expand` method, rather than relying on the template syntax.
pip install uri-template
import uri_template
uri_template.expand("{name}", {"name": "value"})uri_template.expand("{var_name}", {"var_name": "value"})