{"id":22114023,"url":"https://github.com/plinss/uri-template","last_synced_at":"2026-03-12T00:01:49.715Z","repository":{"id":43216782,"uuid":"236412526","full_name":"plinss/uri-template","owner":"plinss","description":"Mirror of https://gitlab.linss.com/open-source/python/uri-template/ ","archived":false,"fork":false,"pushed_at":"2023-06-21T02:44:19.000Z","size":65,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-07T12:16:16.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plinss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-27T03:18:59.000Z","updated_at":"2023-04-10T04:14:14.000Z","dependencies_parsed_at":"2022-09-11T23:41:27.814Z","dependency_job_id":"e67eef4e-407f-4856-b320-740a9fb6dc8d","html_url":"https://github.com/plinss/uri-template","commit_stats":null,"previous_names":["plinss/uri_template"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/plinss/uri-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plinss%2Furi-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plinss%2Furi-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plinss%2Furi-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plinss%2Furi-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plinss","download_url":"https://codeload.github.com/plinss/uri-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plinss%2Furi-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27671995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T11:08:23.603Z","updated_at":"2025-12-11T22:45:57.774Z","avatar_url":"https://github.com/plinss.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uri-template\n\nAn implementation of RFC 6570 URI Templates.\n\nThis packages implements URI Template expansion in strict adherence to RFC 6570,\nbut adds a few extensions.\n\n## RFC 6570 Extensions\n\n### Non-string Values\n\nRFC 6570 is silent regarding variable values that are not strings, lists, associative arrays, or null.\n\nThis package handles value types as follows:\n\n  * Values that are instances of `str` are treated as strings.\n  * Values implementing `collections.abc.Sequence` are treated as lists.\n  * Values implementing `collections.abc.Mapping` are treated as associative arrays.\n  * `None` values are treated as null.\n  * Boolean values are converted to the lower case strings 'true' and 'false'.\n  * All other values will be converted to strings using the Python `str()` function.\n\n### Nested Structures\n\nThis package handles variable values with nested structure,\nfor example, lists containing other lists or associative arrays,\nor associative arrays containing lists or other associative arrays.\n\nNested values for variables that do not use the array modifier ('[]') are treated as follows:\n\n  * Lists containing lists are flattened into a single list.\n  * Lists containing associative arrays are treated as a single combined associative array.\n  * Associative arrays represent nested data using dot notation (\".\") for the variable names.\n\nNested values for variables that use the array modifier extend the variable name with \nthe value's index or key written as an array subscript, e.g. \"foo[0]\" or \"foo[bar]\".\n\n### Default Values\n\nThis package allows default string values for variables per early drafts of RFC 6570.\ne.g. \"{foo=bar}\" will expand to \"bar\" if a value for `foo` is not given.\n\nList and associtative array default values are not supported at this time.\n\n### Specifying Value Keys\n\nSometimes a URI Template is used to provide glue between an API and a given set of data.\nIn this case, the names of values needed in the final URL may not match the data provided \nfor the expansion.\n\nThis package allows specifying the key used to pass data into the template. \ne.g. \"{?foo/bar}\" will expand to \"?foo=\u003cthe value provided as bar\u003e\"\n\n### Partial expansion\n\nThis package allows partial expansion of URI Templates.\n\nIn a partial expansion, missing values preseve their expansion in the resultant output.\ne.g. a partial expansion of \"{one}/{two}\" with a value for `one` of \"foo\" and `two` missing will result in:\n\"foo/{two}\".\n\nIn order to allow partial expansions to preserve value joiners with expanded output,\nexpansions accept an optional \"trailing joiner\" of \",\", \".\", \"/\", \";\", or \"\u0026\",\nif this joiner is present after all variables, \nit will be appended to the output of the expansion and will suppress the output prefix.\ne.g.: \"{#one,two}\" with a missing value for `one` and a value of \"bar\" for `two`, \nwill partially expand to: \"#{#one,}bar\", which when provided with a value of \"foo\" for `one` \nwill expand to \"#foo,bar\"\n\nSome partial expansions that have some output, but have missing values, \nwill convert the remaining variables to a different type of expansion so that \nfurther expansions will produce the same output as if all values were originally present.\n\n   * Partial Simple String Expansions will convert to Comma Expansions.\n   * Partial Reserved Expansions Partial Fragment Expansions will convert to Reserved Comma Expansions.\n   * Partial Form-Style Query Expansions will convert to Form-Style Query Continuations.\n\nIn order to preserve the resultant value of templates that are paritally expanded, \nthe following additional Expression Expansions are supported:\n\n#### Comma Expansion: {,var}\n\nSimilar to Label Expansion with Dot-Prefix, \nComma Expansion prefixes the expansion output with a single comma \",\".\n\n#### Reserved Comma Expansion: {,+var}\n\nSimilar to Comma Expansion, \nReserved Comma Expansion prefixes the expansion output with a single comma \",\",\nbut otherwise performs a Reserved Expansion ({+var}).\n\n## API \n\nThe package provides three functions:\n\n#### uri_template.expand(template: str, **kwargs) -\u003e (str | None): ...\n\nExpand the given template, skipping missing values per RFC 6570.\n\nReturns `None` if the template is invalid or expansion fails.\n\n\n#### uri_template.partial(template: str, **kwargs) -\u003e (str | None): ...\n\nPartially expand the given template, \nreplacing missing variables with further expansions.\n\nReturns `None` if the template is invalid or expansion fails.\n\n\n#### uri_template.validate(template: str) -\u003e bool: ...\n\nReturn `True` if the template is valid.\n\n---\n\nAnd the following classes:\n\n### uri_template.URITemplate\n\n#### URITemplate(template: str)\n\nConstruct a URITemplate for a given template string.\n\nRaises `ExpansionInvalid`, `ExpansionReserved`, or `VariableInvalid` if the template is invalid or unsupported.\n\n#### URITemplate.variables: Iterable[Variable]\n\nAll variables present in the template.\nDuplicates are returned once, order is preserved.\n\n#### URITemplate.variable_names: Iterable[str]\n\nThe names of all variables present in the template.\nDuplicates are returned once, order is preserved.\n\n#### URITemplate.expanded: bool\n\nDetermine if template is fully expanded.\n\n#### URITemplate.expand(**kwargs) -\u003e str\n\nReturns the result of the expansion, skips missing variables.\n\nRaises `ExpansionFailed` if the expansion fails due to a composite value being passed to a variable with a prefix modifier.\n\n#### URITemplate.partial(**kwargs) -\u003e URITemplate\n\nExpand the template, replacing missing variables with further expansions.\n\nRaises `ExpansionFailed` if the expansion fails due to a composite value being passed to a variable with a prefix modifier.\n\n#### URITemplate.__str__() -\u003e str\n\nConvert the URITemplate object back into its original string form.\n\n---\n\n### uri_template.Variable\n\n#### Variable(var_spec: str)\n\nConstruct a Variable.\n\n#### Variable.name: str\n\nThe name of the variable\n\n#### Variable.max_length: int\n\nThe speicified max length, or `0`.\n\n#### Variable.explode: bool\n\nExplode modifier is present.\n\n#### Variable.array: bool\n\nArray modifier is present.\n\n#### Variable.default: (str | None)\n\nSpecified default value, or `None`.\n\n#### Variable.__str__() -\u003e str\n\nConvert the variable back to its original string form.\n\n---\n\nAnd the following exceptions:\n\n#### uri_template.ExpansionInvalid\n\nExpansion specification is invalid. \n\nRaised by URITemplate constructor.\n\n#### uri_template.ExpansionReserved\n\nExpansion contains a reserved operator.\n\nRaised by URITemplate constructor.\n\n#### uri_template.VariableInvalid\n\nVariable specification is invalid.\n\nRaised by URITemplate constructor.\n\n#### uri_template.ExpansionFailed\n\nExpansion failed, currently only possible when a composite value is passed to a variable with a prefix modifier.\n\nRaised by URITemplate.expand() or URITemplate.partial() methods.\n\n\n## Installation\n\nInstall with pip:\n\n    pip install uri-template","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplinss%2Furi-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplinss%2Furi-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplinss%2Furi-template/lists"}