stac-validator


Namestac-validator JSON
Version 3.3.2 PyPI version JSON
download
home_pagehttps://github.com/stac-utils/stac-validator
SummaryA package to validate STAC files
upload_time2023-11-17 18:16:23
maintainer
docs_urlNone
authorJames Banting, Jonathan Healy
requires_python>=3.8
licenseMIT
keywords stac validation raster
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.7+
  - Requests
  - Click
  - Pytest
  - 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        |


---

# 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`.
  --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": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "STAC validation raster",
    "author": "James Banting, Jonathan Healy",
    "author_email": "jhealy@sparkgeo.com",
    "download_url": "https://files.pythonhosted.org/packages/5d/b7/c5d77b1ecc9d2cc10ec4790ee4d783ebcfa783196f4c4a440e3ced31d8ab/stac_validator-3.3.2.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\n## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).   \n    \n\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.7+\n  - Requests\n  - Click\n  - Pytest\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\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\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  --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)\nAn example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)\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# Testing\n\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# 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**--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": "MIT",
    "summary": "A package to validate STAC files",
    "version": "3.3.2",
    "project_urls": {
        "Homepage": "https://github.com/stac-utils/stac-validator"
    },
    "split_keywords": [
        "stac",
        "validation",
        "raster"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5db7c5d77b1ecc9d2cc10ec4790ee4d783ebcfa783196f4c4a440e3ced31d8ab",
                "md5": "521981e9c1f3db2dfbb779e6ab06f53f",
                "sha256": "95964d17dfeb7134a0fd132146e813c1635f4f72772e9cbbe06e81a37ad9c6ba"
            },
            "downloads": -1,
            "filename": "stac_validator-3.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "521981e9c1f3db2dfbb779e6ab06f53f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 22629,
            "upload_time": "2023-11-17T18:16:23",
            "upload_time_iso_8601": "2023-11-17T18:16:23.915603Z",
            "url": "https://files.pythonhosted.org/packages/5d/b7/c5d77b1ecc9d2cc10ec4790ee4d783ebcfa783196f4c4a440e3ced31d8ab/stac_validator-3.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-17 18:16:23",
    "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"
}
        
Elapsed time: 0.14537s