jschon.catalog
- class jschon.catalog.Catalog(name='catalog')
The
Catalog
acts as a schema cache, enabling schemas and subschemas to be indexed, re-used, and cross-referenced by URI.- Parameters
name (str) –
- Return type
None
- __init__(name='catalog')
Initialize a
Catalog
instance.- Parameters
name (str) – a unique name for this
Catalog
instance- Return type
None
- add_schema(uri, schema, *, cacheid='default')
Add a (sub)schema to a cache.
- Parameters
uri (jschon.uri.URI) – the URI identifying the (sub)schema
schema (jschon.jsonschema.JSONSchema) – the
JSONSchema
instance to cachecacheid (Hashable) – schema cache identifier
- Return type
None
- add_uri_source(base_uri, source)
Register a source for URI-identified JSON resources.
- Parameters
base_uri (jschon.uri.URI) – a normalized, absolute URI - including scheme, without a fragment, and ending with
'/'
source (jschon.catalog.Source) – a
Source
object
- Raises
CatalogError – if base_uri is invalid
- cache(cacheid=None)
Context manager for a schema cache.
Example usage:
with catalog.cache() as cacheid: schema = JSONSchema(..., cacheid=cacheid)
The cache and its contents are popped from the catalog upon exiting the
with
block.- Parameters
cacheid (Hashable) –
- Return type
AbstractContextManager[Hashable]
- create_metaschema(uri, core_vocabulary_uri, *default_vocabulary_uris, **kwargs)
Create, cache and validate a
Metaschema
.- Parameters
uri (jschon.uri.URI) – the URI identifying the metaschema
core_vocabulary_uri (jschon.uri.URI) – the URI identifying the metaschema’s core
Vocabulary
default_vocabulary_uris (jschon.uri.URI) – default
Vocabulary
URIs, used in the absence of a"$vocabulary"
keyword in the metaschema JSON filekwargs (Any) – additional keyword arguments to pass through to the
JSONSchema
constructor
- Return type
None
- create_vocabulary(uri, *kwclasses)
Create a
Vocabulary
object, which may be used by aMetaschema
to provide keyword classes used in schema construction.- Parameters
uri (jschon.uri.URI) – the URI identifying the vocabulary
kwclasses (Type[jschon.vocabulary.Keyword]) – the
Keyword
classes constituting the vocabulary
- Return type
None
- del_schema(uri, *, cacheid='default')
Remove a (sub)schema from a cache.
- Parameters
uri (jschon.uri.URI) – the URI identifying the (sub)schema
cacheid (Hashable) – schema cache identifier
- Return type
None
- enable_formats(*format_attr)
Enable validation of the specified format attributes.
These may include formats defined in
jschon.formats
and elsewhere.- Parameters
format_attr (str) –
- Return type
None
- classmethod get_catalog(name='catalog')
- Parameters
name (str) –
- Return type
- get_schema(uri, *, metaschema_uri=None, cacheid='default')
Get a (sub)schema identified by uri from a cache, or load it from disk if not already cached.
- Parameters
uri (jschon.uri.URI) – the URI identifying the (sub)schema
metaschema_uri (Optional[jschon.uri.URI]) – passed to the
JSONSchema
constructor when loading a new instance from diskcacheid (Hashable) – schema cache identifier
- Raises
CatalogError – if a schema cannot be found for uri, or if the object referenced by uri is not a
JSONSchema
- Return type
- get_vocabulary(uri)
Get a
Vocabulary
by its uri.- Parameters
uri (jschon.uri.URI) – the URI identifying the vocabulary
- Raises
CatalogError – if uri is not a recognized vocabulary URI
- Return type
- is_format_enabled(format_attr)
Return True if validation is enabled for format_attr, False otherwise.
- Return type
bool
- load_json(uri)
Load a JSON-compatible object from the source for uri.
If there are multiple candidate base URIs for uri, the most specific match (i.e. the longest one) is selected.
- Parameters
uri (jschon.uri.URI) – a normalized, absolute URI - including scheme, without a fragment
- Raises
CatalogError – if uri is invalid, a source is not available for uri, or if a loading error occurs
- Return type
Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]]
- class jschon.catalog.LocalSource(base_dir, **kwargs)
- Parameters
base_dir (Union[str, PathLike]) –
kwargs (Any) –
- Return type
None
- __call__(relative_path)
- Parameters
relative_path (str) –
- Return type
Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]]
- __init__(base_dir, **kwargs)
- Parameters
base_dir (Union[str, os.PathLike]) –
kwargs (Any) –
- Return type
None
- class jschon.catalog.RemoteSource(base_url, **kwargs)
- Parameters
base_url (URI) –
kwargs (Any) –
- Return type
None
- __call__(relative_path)
- Parameters
relative_path (str) –
- Return type
Union[None, bool, int, float, str, Sequence[Any], Mapping[str, Any]]
- __init__(base_url, **kwargs)
- Parameters
base_url (jschon.uri.URI) –
kwargs (Any) –
- Return type
None