# SpatioTemporal Asset Catalog (STAC) Validator
## Documentation
[read the docs](https://stac-validator.readthedocs.io/en/latest/)
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
```bash
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
[
{
"version": "1.0.0",
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
"schema": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json",
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": true,
"asset_type": "ITEM",
"validation_method": "default"
}
]
```
## Requirements
- Python 3.8+
- Requests
- Click
- Jsonschema
Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.
https://github.com/stac-utils/stac-check
## Install
Installation from PyPi
```bash
pip install stac-validator
```
Installation from Repo
```bash
pip install .
```
or for local development
```bash
pip install -e '.[dev]'
```
The [Makefile](./Makefile) has convenience commands if Make is installed.
```bash
make help
```
## Versions supported
| STAC |
| ------------ |
| 0.8.0 |
| 0.8.1 |
| 0.9.0 |
| 1.0.0-beta.1 |
| 1.0.0-beta.2 |
| 1.0.0-rc.1 |
| 1.0.0-rc.2 |
| 1.0.0-rc.3 |
| 1.0.0-rc.4 |
| 1.0.0 |
| 1.1.0-beta.1 |
| 1.1.0 |
---
# CLI
**Basic Usage**
```bash
stac-validator --help
Usage: stac-validator [OPTIONS] STAC_FILE
Options:
--core Validate core stac object only without extensions.
--extensions Validate extensions only.
--links Additionally validate links. Only works with
default mode.
--assets Additionally validate assets. Only works with
default mode.
-c, --custom TEXT Validate against a custom schema (local filepath or
remote schema).
-r, --recursive Recursively validate all related stac objects.
-m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this
argument to get full recursion. Ignored if
`recursive == False`.
--collections Validate /collections response.
--item-collection Validate item collection response. Can be combined
with --pages. Defaults to one page.
-p, --pages INTEGER Maximum number of pages to validate via --item-
collection. Defaults to one page.
-v, --verbose Enables verbose output for recursive mode.
--no_output Do not print output to console.
--log_file TEXT Save full recursive output to log file (local
filepath).
--version Show the version and exit.
--help Show this message and exit.
```
---
# Deployment
## Docker
The validator can run using docker containers.
```bash
docker build -t stac-validator .
docker run stac-validator https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json
[
{
"version": "1.0.0",
"path": "https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json",
"schema": [
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": true,
"asset_type": "ITEM",
"validation_method": "default"
}
]
```
## AWS (CDK)
An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
```bash
cd cdk-deployment
cdk diff
```
---
# Python
**Remote source**
```python
from stac_validator import stac_validator
stac = stac_validator.StacValidate("https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json")
stac.run()
print(stac.message)
[
{
"version": "0.9.0",
"path": "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json",
"schema": [
"https://cdn.staclint.com/v0.9.0/collection.json"
],
"valid_stac": true,
"asset_type": "COLLECTION",
"validation_method": "default"
}
]
```
**Local file**
```python
from stac_validator import stac_validator
stac = stac_validator.StacValidate("tests/test_data/1beta1/sentinel2.json", extensions=True)
stac.run()
print(stac.message)
[
{
"version": "1.0.0-beta.1",
"path": "tests/test_data/1beta1/sentinel2.json",
"schema": [
"https://cdn.staclint.com/v1.0.0-beta.1/collection.json"
],
"valid_stac": true,
"asset_type": "COLLECTION",
"validation_method": "extensions"
}
]
```
**Dictionary**
```python
from stac_validator import stac_validator
stac = stac_validator.StacValidate()
stac.validate_dict(dictionary)
print(stac.message)
```
**Item Collection**
```python
from stac_validator import stac_validator
stac = stac_validator.StacValidate()
stac.validate_item_collection_dict(item_collection_dict)
print(stac.message)
```
---
# Testing
```bash
make test
# or
pytest -v
```
See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
---
# Additional Examples
**--core**
```bash
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --core
[
{
"version": "1.0.0",
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": true,
"asset_type": "ITEM",
"validation_method": "core"
}
]
```
**--custom**
```bash
stac-validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json
[
{
"version": "0.7.0",
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
"schema": [
"https://cdn.staclint.com/v0.7.0/catalog.json"
],
"asset_type": "CATALOG",
"validation_method": "custom",
"valid_stac": true
}
]
```
**--extensions**
```bash
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions
[
{
"version": "1.0.0",
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
"schema": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
],
"valid_stac": true,
"asset_type": "ITEM",
"validation_method": "extensions"
}
]
```
**--recursive**
```bash
stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --verbose
[
{
"version": "0.8.1",
"path": "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot4_orthoimages/collection.json",
"schema": "https://cdn.staclint.com/v0.8.1/collection.json",
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": true
},
{
"version": "0.8.1",
"path": "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/collection.json",
"schema": "https://cdn.staclint.com/v0.8.1/collection.json",
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": true
},
{
"version": "0.8.1",
"path": "https://spot-canada-ortho.s3.amazonaws.com/catalog.json",
"schema": "https://cdn.staclint.com/v0.8.1/catalog.json",
"asset_type": "CATALOG",
"validation_method": "recursive",
"valid_stac": true
}
]
```
**--item-collection**
```bash
stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
```
Raw data
{
"_id": null,
"home_page": "https://github.com/stac-utils/stac-validator",
"name": "stac-validator",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "STAC validation raster",
"author": "James Banting, Jonathan Healy",
"author_email": "jonathan.d.healy@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f5/75/60f270fcb909a03227c50725349e2ba0410fb2e0a88cacf4f2d1fe70aed5/stac_validator-3.4.0.tar.gz",
"platform": null,
"description": "# SpatioTemporal Asset Catalog (STAC) Validator\n\n## Documentation\n\n[read the docs](https://stac-validator.readthedocs.io/en/latest/)\n\n## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).\n\n```bash\nstac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json\n[\n {\n \"version\": \"1.0.0\",\n \"path\": \"https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json\",\n \"schema\": [\n \"https://stac-extensions.github.io/eo/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/projection/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/scientific/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/view/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json\",\n \"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"ITEM\",\n \"validation_method\": \"default\"\n }\n]\n```\n\n## Requirements\n\n- Python 3.8+\n - Requests\n - Click\n - Jsonschema\n\nNote: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document. \nhttps://github.com/stac-utils/stac-check\n\n## Install\n\nInstallation from PyPi\n\n```bash\npip install stac-validator\n```\n\nInstallation from Repo\n\n```bash\npip install .\n```\n\nor for local development\n\n```bash\npip install -e '.[dev]'\n```\n\nThe [Makefile](./Makefile) has convenience commands if Make is installed.\n\n```bash\nmake help\n```\n\n## Versions supported\n\n| STAC |\n| ------------ |\n| 0.8.0 |\n| 0.8.1 |\n| 0.9.0 |\n| 1.0.0-beta.1 |\n| 1.0.0-beta.2 |\n| 1.0.0-rc.1 |\n| 1.0.0-rc.2 |\n| 1.0.0-rc.3 |\n| 1.0.0-rc.4 |\n| 1.0.0 |\n| 1.1.0-beta.1 |\n| 1.1.0 |\n\n---\n\n# CLI\n\n**Basic Usage**\n\n```bash\nstac-validator --help\nUsage: stac-validator [OPTIONS] STAC_FILE\n\nOptions:\n --core Validate core stac object only without extensions.\n --extensions Validate extensions only.\n --links Additionally validate links. Only works with\n default mode.\n --assets Additionally validate assets. Only works with\n default mode.\n -c, --custom TEXT Validate against a custom schema (local filepath or\n remote schema).\n -r, --recursive Recursively validate all related stac objects.\n -m, --max-depth INTEGER Maximum depth to traverse when recursing. Omit this\n argument to get full recursion. Ignored if\n `recursive == False`.\n --collections Validate /collections response.\n --item-collection Validate item collection response. Can be combined\n with --pages. Defaults to one page.\n -p, --pages INTEGER Maximum number of pages to validate via --item-\n collection. Defaults to one page.\n -v, --verbose Enables verbose output for recursive mode.\n --no_output Do not print output to console.\n --log_file TEXT Save full recursive output to log file (local\n filepath).\n --version Show the version and exit.\n --help Show this message and exit.\n```\n\n---\n\n# Deployment\n\n## Docker\n\nThe validator can run using docker containers.\n\n```bash\ndocker build -t stac-validator .\ndocker run stac-validator https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json\n[\n {\n \"version\": \"1.0.0\",\n \"path\": \"https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json\",\n \"schema\": [\n \"https://stac-extensions.github.io/projection/v1.0.0/schema.json\",\n \"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"ITEM\",\n \"validation_method\": \"default\"\n }\n]\n```\n\n## AWS (CDK)\n\nAn example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)\n\n```bash\ncd cdk-deployment\ncdk diff\n```\n\n---\n\n# Python\n\n**Remote source**\n\n```python\nfrom stac_validator import stac_validator\n\nstac = stac_validator.StacValidate(\"https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json\")\nstac.run()\nprint(stac.message)\n[\n {\n \"version\": \"0.9.0\",\n \"path\": \"https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json\",\n \"schema\": [\n \"https://cdn.staclint.com/v0.9.0/collection.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"COLLECTION\",\n \"validation_method\": \"default\"\n }\n]\n```\n\n**Local file**\n\n```python\nfrom stac_validator import stac_validator\n\nstac = stac_validator.StacValidate(\"tests/test_data/1beta1/sentinel2.json\", extensions=True)\nstac.run()\nprint(stac.message)\n[\n {\n \"version\": \"1.0.0-beta.1\",\n \"path\": \"tests/test_data/1beta1/sentinel2.json\",\n \"schema\": [\n \"https://cdn.staclint.com/v1.0.0-beta.1/collection.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"COLLECTION\",\n \"validation_method\": \"extensions\"\n }\n]\n```\n\n**Dictionary**\n\n```python\nfrom stac_validator import stac_validator\n\nstac = stac_validator.StacValidate()\nstac.validate_dict(dictionary)\nprint(stac.message)\n```\n\n**Item Collection**\n\n```python\nfrom stac_validator import stac_validator\n\nstac = stac_validator.StacValidate()\nstac.validate_item_collection_dict(item_collection_dict)\nprint(stac.message)\n```\n\n---\n\n# Testing\n\n```bash\nmake test\n# or\npytest -v\n```\n\nSee the [tests](./tests/test_stac_validator.py) files for examples on different usages.\n\n---\n\n# Additional Examples\n\n**--core**\n\n```bash\nstac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --core\n[\n {\n \"version\": \"1.0.0\",\n \"path\": \"https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json\",\n \"schema\": [\n \"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"ITEM\",\n \"validation_method\": \"core\"\n }\n]\n```\n\n**--custom**\n\n```bash\nstac-validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json\n[\n {\n \"version\": \"0.7.0\",\n \"path\": \"https://radarstac.s3.amazonaws.com/stac/catalog.json\",\n \"schema\": [\n \"https://cdn.staclint.com/v0.7.0/catalog.json\"\n ],\n \"asset_type\": \"CATALOG\",\n \"validation_method\": \"custom\",\n \"valid_stac\": true\n }\n]\n```\n\n**--extensions**\n\n```bash\nstac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions\n[\n {\n \"version\": \"1.0.0\",\n \"path\": \"https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json\",\n \"schema\": [\n \"https://stac-extensions.github.io/eo/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/projection/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/scientific/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/view/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json\"\n ],\n \"valid_stac\": true,\n \"asset_type\": \"ITEM\",\n \"validation_method\": \"extensions\"\n }\n]\n```\n\n**--recursive**\n\n```bash\nstac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --verbose\n[\n {\n \"version\": \"0.8.1\",\n \"path\": \"https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot4_orthoimages/collection.json\",\n \"schema\": \"https://cdn.staclint.com/v0.8.1/collection.json\",\n \"asset_type\": \"COLLECTION\",\n \"validation_method\": \"recursive\",\n \"valid_stac\": true\n },\n {\n \"version\": \"0.8.1\",\n \"path\": \"https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/collection.json\",\n \"schema\": \"https://cdn.staclint.com/v0.8.1/collection.json\",\n \"asset_type\": \"COLLECTION\",\n \"validation_method\": \"recursive\",\n \"valid_stac\": true\n },\n {\n \"version\": \"0.8.1\",\n \"path\": \"https://spot-canada-ortho.s3.amazonaws.com/catalog.json\",\n \"schema\": \"https://cdn.staclint.com/v0.8.1/catalog.json\",\n \"asset_type\": \"CATALOG\",\n \"validation_method\": \"recursive\",\n \"valid_stac\": true\n }\n]\n```\n\n**--item-collection**\n\n```bash\nstac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A package to validate STAC files",
"version": "3.4.0",
"project_urls": {
"Homepage": "https://github.com/stac-utils/stac-validator"
},
"split_keywords": [
"stac",
"validation",
"raster"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aecba55bcab77b2d4265960d96e302233aaba03b8cc1401750b86b7c92c80271",
"md5": "98ed6c4dbc5cfccd68439c189cb6253f",
"sha256": "881ffba5647c805968d7b610086639727e119296aa5a833e7ff3670e560c0e72"
},
"downloads": -1,
"filename": "stac_validator-3.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "98ed6c4dbc5cfccd68439c189cb6253f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 16650,
"upload_time": "2024-10-08T15:00:46",
"upload_time_iso_8601": "2024-10-08T15:00:46.864334Z",
"url": "https://files.pythonhosted.org/packages/ae/cb/a55bcab77b2d4265960d96e302233aaba03b8cc1401750b86b7c92c80271/stac_validator-3.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f57560f270fcb909a03227c50725349e2ba0410fb2e0a88cacf4f2d1fe70aed5",
"md5": "46c16b773a33e3b5655ec046fa5d6066",
"sha256": "816519ce03f2127fb8fe32542a5b874a348fc49912223661f8d545b247013bf4"
},
"downloads": -1,
"filename": "stac_validator-3.4.0.tar.gz",
"has_sig": false,
"md5_digest": "46c16b773a33e3b5655ec046fa5d6066",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 22876,
"upload_time": "2024-10-08T15:00:48",
"upload_time_iso_8601": "2024-10-08T15:00:48.210228Z",
"url": "https://files.pythonhosted.org/packages/f5/75/60f270fcb909a03227c50725349e2ba0410fb2e0a88cacf4f2d1fe70aed5/stac_validator-3.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-08 15:00:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stac-utils",
"github_project": "stac-validator",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "stac-validator"
}