Skip to main content
`Ctrl`+`K`

# pystac.validation

exception pystac.validation.GetSchemaError(href: str, error: Exception)

  Raised when unable to fetch a schema.

class pystac.validation.JsonSchemaSTACValidator(schema_uri_map: SchemaUriMap | None = None)

  Validate STAC based on JSON Schemas.

  This validator uses JSON schemas, read from URIs provided by a `SchemaUriMap`, to validate STAC core objects and extensions.

  Parameters:

    schema_uri_map – The `SchemaUriMap` that defines where the validator will retrieve the JSON schemas for validation. Defaults to an instance of `DefaultSchemaUriMap`

  Note: This class requires the `jsonschema` library to be installed.

  get_schema_from_uri(schema_uri: str) → tuple[dict[str, Any], Any]

    DEPRECATED

  property registry: Any
  schema_cache: dict[str, dict[str, Any]]
  schema_uri_map: SchemaUriMap
  validate_core(stac_dict: dict[str, Any], stac_object_type: STACObjectType, stac_version: str, href: str | None = None) → str | None

    Validate a core stac object.

    Return value can be None or specific to the implementation.

    Parameters:

      - stac_dict – Dictionary that is the STAC json of the object.

      - stac_object_type – The stac object type of the object encoded in stac_dict. One of `STACObjectType`.

      - stac_version – The version of STAC to validate the object against.

      - href – Optional HREF of the STAC object being validated.

    Returns:

      URI for the JSON schema that was validated against, or None if

        no validation occurred.

    Return type:

      str

    Raises:

      STACValidationError – if stac_dict is not valid. The exception is raised from the “best” error, as determined by the jsonschema library. To access all jsonschema validation errors, use `STACValidationError.source`.

  validate_extension(stac_dict: dict[str, Any], stac_object_type: STACObjectType, stac_version: str, extension_id: str, href: str | None = None) → str | None

    Validate an extension stac object.

    Return value can be None or specific to the implementation.

    Parameters:

      - stac_dict – Dictionary that is the STAC json of the object.

      - stac_object_type – The stac object type of the object encoded in stac_dict. One of `STACObjectType`.

      - stac_version – The version of STAC to validate the object against.

      - extension_id – The extension ID to validate against.

      - href – Optional HREF of the STAC object being validated.

    Returns:

      URI for the JSON schema that was validated against, or None if

        no validation occurred.

    Return type:

      str

    Raises:

      STACValidationError – if stac_dict is not valid. The exception is raised from the “best” error, as determined by the jsonschema library. To access all jsonschema validation errors, use `STACValidationError.source`.

class pystac.validation.RegisteredValidator
  classmethod get_validator() → STACValidator
  classmethod set_validator(validator: STACValidator) → None

pystac.validation.set_validator(validator: STACValidator) → None

  Sets the STACValidator to use in PySTAC.

  Parameters:

    validator – The STACValidator implementation to use for validation.

pystac.validation.validate(stac_object: STACObject, validator: STACValidator | None = None) → list[Any]

  Validates a `STACObject`.

  Parameters:

    - stac_object – The stac object to validate.

    - validator – A custom validator to use for validation of the STAC object. If omitted, the default validator from `RegisteredValidator` will be used instead.

  Returns:

    List of return values from the validation calls for the

      core object and any extensions. Element type is specific to the STACValidator implementation.

  Return type:

    List[Any]

  Raises:

    STACValidationError –

pystac.validation.validate_all(stac_object: STACObject | dict[str, Any], href: str | None = None, stac_io: pystac.StacIO | None = None) → None

  Validate a `STACObject`, or a STAC object serialized as JSON into a dict.

  If the STAC object represents a catalog or collection, this function will be called recursively for each child link and all contained items.

  Parameters:

    - stac_object – STAC object to validate

    - href – HREF of the STAC object being validated. Used for error reporting and resolving relative links.

    - stac_io – Optional StacIO instance to use for reading hrefs. If None, the StacIO.default() instance is used.

  Raises:

    STACValidationError or ValueError – STACValidationError is raised if the STAC object or any contained catalog, collection, or item has a validation error. ValueError is raised if stac_object is a STACObject and href is not None, or if stac_object is a dict and href is None.

pystac.validation.validate_all_dict(stac_dict: dict[str, Any], href: str | None, stac_io: StacIO | None = None) → None

  Validate a stac object serialized as JSON into a dict.

  If the STAC object represents a catalog or collection, this function will be called recursively for each child link and all contained items.

  Parameters:

    - stac_dict – Dictionary that is the STAC json of the object.

    - href – HREF of the STAC object being validated. Used for error reporting and resolving relative links.

    - stac_io – Optional StacIO instance to use for reading hrefs. If None, the StacIO.default() instance is used.

  Raises:

    STACValidationError – if the STAC object or any contained catalog, collection, or item has a validation error

pystac.validation.validate_dict(stac_dict: dict[str, Any], stac_object_type: STACObjectType | None = None, stac_version: str | None = None, extensions: list[str] | None = None, href: str | None = None, validator: STACValidator | None = None) → list[Any]

  Validate a stac object serialized as JSON into a dict.

  This method delegates to the call to `validate()` for the `STACValidator` registered via `set_validator()` or `JsonSchemaSTACValidator` by default.

  Parameters:

    - stac_dict – Dictionary that is the STAC json of the object.

    - stac_object_type – The stac object type of the object encoded in stac_dict. One of `STACObjectType`. If not supplied, this will use PySTAC’s identification logic to identify the object type.

    - stac_version – The version of STAC to validate the object against. If not supplied, this will use PySTAC’s identification logic to identify the stac version

    - extensions – Extension IDs for this stac object. If not supplied, PySTAC’s identification logic to identify the extensions.

    - href – Optional HREF of the STAC object being validated.

    - validator – A custom validator to use for validation of the STAC dictionary. If omitted, the default validator from `RegisteredValidator` will be used instead.

  Returns:

    List of return values from the validation calls for the

      core object and any extensions. Element type is specific to the STACValidator implementation.

  Return type:

    List[Any]

  Raises:

    STACValidationError –