jsonschema_extras.registries.retrieval package

Helpers related to resource retrieval.

For the default implementation of resource caching, see referencing.retrieval.to_cached_resource(). It uses lru_cache(maxsize=None) as of version 0.37 .

type jsonschema_extras.registries.retrieval.CacheFn = Callable[[Retrieve], Retrieve]

Function decorator for Retrieve to cache retrieved resources by their URIs.

type jsonschema_extras.registries.retrieval.CacheSpecDefault = Literal['default']

Specification for default implementation of caching for retrieved resources.

jsonschema_extras.registries.retrieval.LOADS_FN_JSON_DEFAULT(text, *, loads_kwargs=None)

Deserialize a schema from JSON text

Satisfies LoadTextFn.

Return type:

Any

Parameters:
  • text (str)

  • loads_kwargs (Kwargs | None)

type jsonschema_extras.registries.retrieval.LoadTextFn = Callable[[str], D]
type jsonschema_extras.registries.retrieval.ResourceFromContentsFn = Callable[[D], Resource]

Function to make a Resource from resource contents.

Note

The function is intended to take a deserialized data structure.

Parameters:

D – Resource contents.

Returns:

Produced Resource instance.

Return type:

Resource[D]

type jsonschema_extras.registries.retrieval.RetrieveTextFn = Callable[[str], str]

Function to retrieve serialized resource data by URI

Parameters:

str – Resource URI.

Returns:

Retrieved serialized resource representation.

Return type:

str

jsonschema_extras.registries.retrieval.schema_data_from_json_text(text, *, loads_kwargs=None)[source]

Deserialize a schema from JSON text

Satisfies LoadTextFn.

Return type:

Any

Parameters:
  • text (str)

  • loads_kwargs (Kwargs | None)

jsonschema_extras.registries.retrieval.to_cached_resource(cache=None, loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]

Build a decorator to make a resource retrieval callable out of a RetrieveTextFn with caching.

RetrieveTextFn retrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating a Resource and caching.

Parameters:
Return type:

Callable[[RetrieveTextFn], Retrieve[TypeVar(D)]]

Returns:

Decorator taking a text retriever RetrieveTextFn and returning a caching resource retriever.

jsonschema_extras.registries.retrieval.to_maybe_cached_resource(cache=None, loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]

Build a decorator to make a resource retrieval callable out of a RetrieveTextFn with optional caching.

RetrieveTextFn retrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating a Resource and optional caching.

Parameters:
Return type:

Callable[[RetrieveTextFn], Retrieve[TypeVar(D)]]

Returns:

Decorator taking a text retriever RetrieveTextFn and returning a resource retriever.

jsonschema_extras.registries.retrieval.to_resource(loads=<function schema_data_from_json_text>, from_contents=<bound method Resource.from_contents of <class 'referencing._core.Resource'>>)[source]

Build a decorator to make a resource retrieval callable out of a RetrieveTextFn.

RetrieveTextFn retrieves serialized representation by URI. A decorator produced by this function adds deserialization (loads), creating a Resource (with no caching).

Parameters:
  • loads (GenericAlias[TypeVar(D)]) – Function to deserialize resource contents (for example, JSON data structure from JSON string). Default: LOADS_FN_JSON_DEFAULT (for JSON).

  • from_contents (GenericAlias[TypeVar(D)]) – Function to produce a Resource from deserialized resource contents. Default: from_contents().

Return type:

Callable[[RetrieveTextFn], Retrieve[TypeVar(D)]]

Returns:

Decorator taking a text retriever RetrieveTextFn and returning a caching resource retriever.

Submodules