A package to validate STAC files
Project description
Spatial Temporal Asset Catalog (STAC) Validator
This utility allows users to validate STAC json files against the STAC spec.
It can be installed as command line utility and passed either a local file path or a url along with the STAC version to validate against. Example usages can be found below
Requirements
- Python 3.6
- Requests
- Docopt
- Pytest
- Pystac
- Jsonschema
Installation from repo
pip install .
or (for development)
pip install --editable .
Installation from PyPi
pip install stac-validator
stac_validator --help
Description: Validate a STAC item or catalog against the STAC specification.
Usage:
stac_validator <stac_file> [--version STAC_VERSION] [--timer] [--recursive] [--log_level LOGLEVEL] [--custom CUSTOM] [--update] [--force] [--extension EXTENSION] [--core] [--legacy]
Arguments:
stac_file Fully qualified path or url to a STAC file.
Options:
-v, --version STAC_VERSION Version to validate against. [default: missing]
-h, --help Show this screen.
--timer Reports time to validate the STAC. (seconds)
--update Migrate to newest STAC version (1.0.0-beta.2) for testing
--log_level LOGLEVEL Standard level of logging to report. [default: CRITICAL]
--custom CUSTOM Validate against a custom schema whether local or remote
--force Set version='0.9.0' and fix missing id for older objects to force validation
--recursive Recursively validate an entire collection or catalog.
--extension EXTENSION Validate an extension
--core Validate on core only
--legacy Validate on older schemas, must be accompanied by --version
CLI
Basic Usage
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/catalog-spec/examples/catalog.json
[
{
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/catalog-spec/examples/catalog.json",
"id": "NAIP",
"asset_type": "catalog",
"validated_version": "1.0.0-beta.2",
"valid_stac": true
}
]
--version
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/catalog-spec/examples/catalog.json --version 0.9.0
[
{
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/catalog-spec/examples/catalog.json",
"id": "NAIP",
"asset_type": "catalog",
"validated_version": "0.9.0",
"valid_stac": false,
"error_type": "STACValidationError",
"error_message": "STAC Validation Error: Validation failed for CATALOG with ID NAIP against schema at https://raw.githubusercontent.com/radiantearth/stac-spec/v0.9.0/catalog-spec/json-schema/catalog.json"
}
]
--extension
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/item-spec/examples/sample-full.json --extension sat
[
{
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/item-spec/examples/sample-full.json",
"id": "CS3-20160503_132131_05",
"asset_type": "item",
"validated_version": "1.0.0-beta.2",
"extension_flag": "sat",
"valid_stac": false,
"error_type": "STACValidationError",
"error_message": "STAC Validation Error: Validation failed for ITEM with ID CS3-20160503_132131_05 against schema at https://schemas.stacspec.org/v1.0.0-beta.2/extensions/sat/json-schema/schema.jsonfor STAC extension 'sat'"
}
]
--update
stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --update
[
{
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
"asset_type": "catalog",
"id": "radarstac",
"original_verson": "0.7.0",
"update": true,
"diff": {
"stac_version": [
"0.7.0",
"1.0.0-beta.2"
],
"stac_extensions": [
"<KEYNOTFOUND>",
[]
]
},
"validated_version": "1.0.0-beta.2",
"valid_stac": true
}
]
--force
stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --force
[
{
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
"asset_type": "catalog",
"original_version": "0.7.0",
"force": true,
"id": "radarstac",
"validated_version": "0.9.0",
"valid_stac": true
}
]
--legacy (must be accompanied by --version)
stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --legacy --version 0.7.0
[
{
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
"asset_type": "catalog",
"schema": "https://cdn.staclint.com/v0.7.0/catalog.json",
"legacy": true,
"validated_version": "v0.7.0"
}
]
--custom
stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json
[
{
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
"asset_type": "catalog",
"schema": "https://cdn.staclint.com/v0.7.0/catalog.json",
"custom": true,
"valid_stac": true
}
]
Testing
pytest -v
See the tests directory for examples on different usages.
Import stac-validator
remote source
from stac_validator import stac_validator
stac = stac_validator.StacValidate("https://raw.githubusercontent.com/radiantearth/stac-spec/master/item-spec/examples/sample-full.json")
stac.run()
print(stac.message)
if stac.message[0]["valid_stac"] == False:
print("False")
local file
from stac_validator import stac_validator
stac = stac_validator.StacValidate("tests/sample-full.json", extension='eo', update=True)
stac.run()
print(stac.message)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stac_validator-1.0.1.tar.gz
(9.3 kB
view details)
Built Distribution
File details
Details for the file stac_validator-1.0.1.tar.gz
.
File metadata
- Download URL: stac_validator-1.0.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df9b8e075a03decf435b9b1531f370a08d0b01890098f7db68e912554296b5c2 |
|
MD5 | c6697f1bf5c831c9de462db1fb30e01a |
|
BLAKE2b-256 | 6bfbdcd12ac62b7450ca2fd348e76017faa323967414707fb6ebc2e63b107892 |
File details
Details for the file stac_validator-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: stac_validator-1.0.1-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39b5c7c1637e81d465a6dd839e0e4cf44ba8b4a2701b25eca967485121f280f7 |
|
MD5 | 9885d4241c19523e1e0a51305b1e34c4 |
|
BLAKE2b-256 | 356e8855ee8adaf6adc4fd3b00b9dc0491f3ce05131c1503a758901661f1916b |