Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
An implementation of RFC 6570 URI Templates.
This packages implements URI Template expansion in strict adherence to RFC 6570, but adds a few extensions.
RFC 6570 is silent regarding variable values that are not strings, lists, associative arrays, or null.
This package handles value types as follows:
str
are treated as strings.collections.abc.Sequence
are treated as lists.collections.abc.Mapping
are treated as associative arrays.None
values are treated as null.str()
function.This package handles variable values with nested structure, for example, lists containing other lists or associative arrays, or associative arrays containing lists or other associative arrays.
Nested values for variables that do not use the array modifier ('[]') are treated as follows:
Nested values for variables that use the array modifier extend the variable name with the value's index or key written as an array subscript, e.g. "foo[0]" or "foo[bar]".
This package allows default string values for variables per early drafts of RFC 6570.
e.g. "{foo=bar}" will expand to "bar" if a value for foo
is not given.
List and associtative array default values are not supported at this time.
Sometimes a URI Template is used to provide glue between an API and a given set of data. In this case, the names of values needed in the final URL may not match the data provided for the expansion.
This package allows specifying the key used to pass data into the template. e.g. "{?foo/bar}" will expand to "?foo="
This package allows partial expansion of URI Templates.
In a partial expansion, missing values preseve their expansion in the resultant output.
e.g. a partial expansion of "{one}/{two}" with a value for one
of "foo" and two
missing will result in:
"foo/{two}".
In order to allow partial expansions to preserve value joiners with expanded output,
expansions accept an optional "trailing joiner" of ",", ".", "/", ";", or "&",
if this joiner is present after all variables,
it will be appended to the output of the expansion and will suppress the output prefix.
e.g.: "{#one,two}" with a missing value for one
and a value of "bar" for two
,
will partially expand to: "#{#one,}bar", which when provided with a value of "foo" for one
will expand to "#foo,bar"
Some partial expansions that have some output, but have missing values, will convert the remaining variables to a different type of expansion so that further expansions will produce the same output as if all values were originally present.
In order to preserve the resultant value of templates that are paritally expanded, the following additional Expression Expansions are supported:
Similar to Label Expansion with Dot-Prefix, Comma Expansion prefixes the expansion output with a single comma ",".
Similar to Comma Expansion, Reserved Comma Expansion prefixes the expansion output with a single comma ",", but otherwise performs a Reserved Expansion ({+var}).
The package provides three functions:
Expand the given template, skipping missing values per RFC 6570.
Returns None
if the template is invalid or expansion fails.
Partially expand the given template, replacing missing variables with further expansions.
Returns None
if the template is invalid or expansion fails.
Return True
if the template is valid.
And the following classes:
Construct a URITemplate for a given template string.
Raises ExpansionInvalid
, ExpansionReserved
, or VariableInvalid
if the template is invalid or unsupported.
All variables present in the template. Duplicates are returned once, order is preserved.
The names of all variables present in the template. Duplicates are returned once, order is preserved.
Determine if template is fully expanded.
Returns the result of the expansion, skips missing variables.
Raises ExpansionFailed
if the expansion fails due to a composite value being passed to a variable with a prefix modifier.
Expand the template, replacing missing variables with further expansions.
Raises ExpansionFailed
if the expansion fails due to a composite value being passed to a variable with a prefix modifier.
Convert the URITemplate object back into its original string form.
Construct a Variable.
The name of the variable
The speicified max length, or 0
.
Explode modifier is present.
Array modifier is present.
Specified default value, or None
.
Convert the variable back to its original string form.
And the following exceptions:
Expansion specification is invalid.
Raised by URITemplate constructor.
Expansion contains a reserved operator.
Raised by URITemplate constructor.
Variable specification is invalid.
Raised by URITemplate constructor.
Expansion failed, currently only possible when a composite value is passed to a variable with a prefix modifier.
Raised by URITemplate.expand() or URITemplate.partial() methods.
Install with pip:
pip install uri-template
FAQs
RFC 6570 URI Template Processor
We found that uri-template demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.