{"id":1732,"library":"std-uritemplate","title":"URI Template (std-uritemplate)","description":"std-uritemplate is a Python library providing a robust and compliant implementation of RFC 6570, the URI Template specification. It allows users to expand URI templates with provided variables, generating complete URIs. The library is actively maintained, with frequent patch releases within major versions, and is currently at version 2.0.8.","status":"active","version":"2.0.8","language":"en","source_language":"en","source_url":"https://github.com/std-uritemplate/std-uritemplate","tags":["uri-template","rfc6570","url","http","rest"],"install":[{"cmd":"pip install std-uritemplate","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The PyPI package is `std-uritemplate`, but the actual Python module name for import is `uritemplate`.","wrong":"from std_uritemplate import URITemplate","symbol":"URITemplate","correct":"from uritemplate import URITemplate"}],"quickstart":{"code":"from uritemplate import URITemplate\n\ntemplate_str = \"https://example.com/api/{resource}{?id,name}\"\ntpl = URITemplate(template_str)\n\n# Expand with simple variables\nexpanded_uri = tpl.expand(resource=\"users\", id=123, name=\"Alice\")\nprint(f\"Expanded URI: {expanded_uri}\")\n\n# Partial expansion\npartially_expanded_tpl = tpl.partial_expand(resource=\"posts\")\nprint(f\"Partially Expanded URI (with resource): {partially_expanded_tpl.template}\")\n\n# Final expansion of partially expanded template\nfinal_uri = partially_expanded_tpl.expand(id=456)\nprint(f\"Final URI: {final_uri}\")","lang":"python","description":"Initialize a URITemplate object with your template string. Use the `expand` method to fill in variables and generate the final URI. `partial_expand` can be used to expand a subset of variables, returning a new `URITemplate` object with the remaining unexpanded variables."},"warnings":[{"fix":"Migrate existing code to use `URITemplate(template_str).expand(**variables)` instead of `uritemplate.expand(template_str, **variables)`.","message":"Version 2.0.0 introduced a significant API change. The `URITemplate` class is now the primary entry point for working with URI templates, replacing the direct `uritemplate.expand` and `uritemplate.partial_expand` functions.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Instantiate `URITemplate` and call its `expand()` or `partial_expand()` methods. Example: `URITemplate(template).expand(var=value)`.","message":"The standalone functions `uritemplate.expand()` and `uritemplate.partial_expand()` have been deprecated in favor of the methods on the `URITemplate` class.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Consult RFC 6570 for specific behavior of operators and variable types, and test template expansions thoroughly, especially with complex data structures.","message":"The library strictly adheres to RFC 6570. Misunderstandings of the RFC's nuances regarding variable modifiers (e.g., `+`, `#`, `.`, `/`, `;`, `?`, `&`) or how different variable types (simple, lists, dictionaries) are expanded can lead to unexpected URI outputs.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure you use `import uritemplate` or `from uritemplate import ...` after `pip install std-uritemplate`.","message":"The package name for installation is `std-uritemplate`, but the Python module to import is `uritemplate`. This is a common source of `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}