stac-valid 4.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stac_valid-4.2.0.dist-info/METADATA +1218 -0
- stac_valid-4.2.0.dist-info/RECORD +12 -0
- stac_valid-4.2.0.dist-info/WHEEL +5 -0
- stac_valid-4.2.0.dist-info/entry_points.txt +3 -0
- stac_valid-4.2.0.dist-info/licenses/LICENSE +202 -0
- stac_valid-4.2.0.dist-info/top_level.txt +1 -0
- stac_validator/__init__.py +0 -0
- stac_validator/batch_validator.py +520 -0
- stac_validator/fast_validator.py +312 -0
- stac_validator/stac_validator.py +574 -0
- stac_validator/utilities.py +547 -0
- stac_validator/validate.py +1107 -0
|
@@ -0,0 +1,1218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stac_valid
|
|
3
|
+
Version: 4.2.0
|
|
4
|
+
Summary: A package to validate STAC files
|
|
5
|
+
Author-email: Jonathan Healy <jon@healy-hyperspatial.dev>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/stac-utils/stac-validator
|
|
8
|
+
Project-URL: Repository, https://github.com/stac-utils/stac-validator
|
|
9
|
+
Keywords: STAC,validation,raster
|
|
10
|
+
Classifier: Intended Audience :: Information Technology
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests>=2.32.3
|
|
19
|
+
Requires-Dist: jsonschema>=4.23.0
|
|
20
|
+
Requires-Dist: fastjsonschema>=2.21.1
|
|
21
|
+
Requires-Dist: click>=8.1.8
|
|
22
|
+
Requires-Dist: referencing>=0.35.1
|
|
23
|
+
Requires-Dist: pyYAML>=6.0.1
|
|
24
|
+
Requires-Dist: tqdm>=4.66.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: black; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-mypy; extra == "dev"
|
|
29
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
30
|
+
Requires-Dist: requests-mock; extra == "dev"
|
|
31
|
+
Requires-Dist: types-setuptools; extra == "dev"
|
|
32
|
+
Requires-Dist: stac-pydantic>=3.3.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy; extra == "dev"
|
|
34
|
+
Requires-Dist: types-attrs; extra == "dev"
|
|
35
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
36
|
+
Requires-Dist: types-jsonschema; extra == "dev"
|
|
37
|
+
Requires-Dist: types-tqdm; extra == "dev"
|
|
38
|
+
Provides-Extra: pydantic
|
|
39
|
+
Requires-Dist: stac-pydantic>=3.3.0; extra == "pydantic"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# SpatioTemporal Asset Catalog Validator
|
|
43
|
+
|
|
44
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
45
|
+
|
|
46
|
+
<p align="left">
|
|
47
|
+
<img src="https://raw.githubusercontent.com/stac-utils/stac-validator/main/assets/stac-validator.png" width=560>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
[](https://pepy.tech/projects/stac-validator)
|
|
51
|
+
[](https://github.com/stac-utils/stac-validator/graphs/contributors)
|
|
52
|
+
[](https://github.com/stac-utils/stac-validator/stargazers)
|
|
53
|
+
[](https://github.com/stac-utils/stac-validator/network/members)
|
|
54
|
+
[](https://pypi.org/project/stac-validator/)
|
|
55
|
+
[](https://github.com/radiantearth/stac-spec/tree/v1.1.0)
|
|
56
|
+
|
|
57
|
+
## Table of Contents
|
|
58
|
+
|
|
59
|
+
- [Overview](#overview)
|
|
60
|
+
- [Documentation](#documentation)
|
|
61
|
+
- [Requirements](#requirements)
|
|
62
|
+
- [Installation](#install)
|
|
63
|
+
- [Supported STAC Versions](#versions-supported)
|
|
64
|
+
- [Usage](#usage)
|
|
65
|
+
- [CLI](#cli)
|
|
66
|
+
- [Legacy Validation](#legacy-validation)
|
|
67
|
+
- [Batch Validation](#batch-validation)
|
|
68
|
+
- [Fast Validation](#fast-validation)
|
|
69
|
+
- [Python](#python)
|
|
70
|
+
- [Schema Cache Settings](#schema-cache-settings)
|
|
71
|
+
- [Performance Benchmarking](#performance-benchmarking)
|
|
72
|
+
- [Examples](#additional-examples)
|
|
73
|
+
- [Core Validation](#--core)
|
|
74
|
+
- [Custom Schema](#--custom)
|
|
75
|
+
- [Extensions Validation](#--extensions)
|
|
76
|
+
- [Recursive Validation](#--recursive)
|
|
77
|
+
- [Item Collection Validation](#--item-collection)
|
|
78
|
+
- [Using Headers](#--header)
|
|
79
|
+
- [Schema Mapping](#--schema-map)
|
|
80
|
+
- [Schema Config](#--schema-config)
|
|
81
|
+
- [Pydantic Validation](#--pydantic)
|
|
82
|
+
- [Deployment](#deployment)
|
|
83
|
+
- [Docker](#docker)
|
|
84
|
+
- [AWS (CDK)](#aws-cdk)
|
|
85
|
+
- [Testing](#testing)
|
|
86
|
+
- [Related Projects](#related-projects)
|
|
87
|
+
- [Sponsors and Supporters](#sponsors-and-supporters)
|
|
88
|
+
- [Contributing](#contributing)
|
|
89
|
+
- [License](#license)
|
|
90
|
+
|
|
91
|
+
## Overview
|
|
92
|
+
|
|
93
|
+
STAC Validator is a tool to validate [STAC (SpatioTemporal Asset Catalog)](https://github.com/radiantearth/stac-spec) json files against the official STAC specification. It provides both a command-line interface and a Python API for validating STAC objects.
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
For detailed documentation, please visit our [GitHub Pages documentation site](https://stac-utils.github.io/stac-validator/).
|
|
98
|
+
|
|
99
|
+
## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
[
|
|
107
|
+
{
|
|
108
|
+
"version": "1.0.0",
|
|
109
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
|
|
110
|
+
"schema": [
|
|
111
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
112
|
+
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
|
|
113
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
114
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
115
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json",
|
|
116
|
+
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
|
|
117
|
+
],
|
|
118
|
+
"valid_stac": true,
|
|
119
|
+
"asset_type": "ITEM",
|
|
120
|
+
"validation_method": "default"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Requirements
|
|
126
|
+
|
|
127
|
+
- Python 3.8+
|
|
128
|
+
- Requests
|
|
129
|
+
- Click
|
|
130
|
+
- Jsonschema
|
|
131
|
+
|
|
132
|
+
## Related Projects
|
|
133
|
+
|
|
134
|
+
Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.
|
|
135
|
+
https://github.com/stac-utils/stac-check
|
|
136
|
+
|
|
137
|
+
## Install
|
|
138
|
+
|
|
139
|
+
### Installation from PyPi
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
$ pip install stac-valid
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Installation from Repo
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
$ pip install .
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
or for local development
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
$ pip install -e '.[dev]'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The [Makefile](./Makefile) has convenience commands if Make is installed.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
$ make help
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Versions supported
|
|
164
|
+
|
|
165
|
+
| STAC |
|
|
166
|
+
| ------------ |
|
|
167
|
+
| 0.8.0 |
|
|
168
|
+
| 0.8.1 |
|
|
169
|
+
| 0.9.0 |
|
|
170
|
+
| 1.0.0-beta.1 |
|
|
171
|
+
| 1.0.0-beta.2 |
|
|
172
|
+
| 1.0.0-rc.1 |
|
|
173
|
+
| 1.0.0-rc.2 |
|
|
174
|
+
| 1.0.0-rc.3 |
|
|
175
|
+
| 1.0.0-rc.4 |
|
|
176
|
+
| 1.0.0 |
|
|
177
|
+
| 1.1.0-beta.1 |
|
|
178
|
+
| 1.1.0 |
|
|
179
|
+
|
|
180
|
+
## Usage
|
|
181
|
+
|
|
182
|
+
### CLI
|
|
183
|
+
|
|
184
|
+
**Basic Usage**
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
$ stac-validator --help
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
Usage: stac-validator [OPTIONS] COMMAND [ARGS]...
|
|
192
|
+
|
|
193
|
+
STAC Validator - Validate STAC files against the STAC specification.
|
|
194
|
+
|
|
195
|
+
Usage:
|
|
196
|
+
stac-validator validate <file> [options]
|
|
197
|
+
stac-validator batch <files> [options]
|
|
198
|
+
stac-validator batch <file> --item-collection [options]
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
Options:
|
|
202
|
+
--help Show this message and exit.
|
|
203
|
+
|
|
204
|
+
Commands:
|
|
205
|
+
batch Validate multiple STAC files concurrently using all available...
|
|
206
|
+
validate Main function for the `stac-validator` command line tool.
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Validate Command**
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
$ stac-validator validate --help
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
Usage: stac-validator validate [OPTIONS] STAC_FILE
|
|
217
|
+
|
|
218
|
+
Validate a STAC file against the STAC specification.
|
|
219
|
+
|
|
220
|
+
Prints validation results to the console as JSON. Exits with status code 0
|
|
221
|
+
if valid, 1 if invalid.
|
|
222
|
+
|
|
223
|
+
Options:
|
|
224
|
+
--core Validate core stac object only without
|
|
225
|
+
extensions.
|
|
226
|
+
--extensions Validate extensions only.
|
|
227
|
+
--links Additionally validate links. Only works with
|
|
228
|
+
default mode.
|
|
229
|
+
--assets Additionally validate assets. Only works
|
|
230
|
+
with default mode.
|
|
231
|
+
-c, --custom TEXT Validate against a custom schema (local
|
|
232
|
+
filepath or remote schema).
|
|
233
|
+
-sc, --schema-config TEXT Validate against a custom schema config
|
|
234
|
+
(local filepath or remote schema config).
|
|
235
|
+
-s, --schema-map <TEXT TEXT>...
|
|
236
|
+
Schema path to replaced by (local) schema
|
|
237
|
+
path during validation. Can be used multiple
|
|
238
|
+
times.
|
|
239
|
+
-r, --recursive Recursively validate all related stac
|
|
240
|
+
objects.
|
|
241
|
+
-m, --max-depth INTEGER Maximum depth to traverse when recursing.
|
|
242
|
+
Omit this argument to get full recursion.
|
|
243
|
+
Ignored if `recursive == False`.
|
|
244
|
+
--collections Validate /collections response.
|
|
245
|
+
--item-collection Validate item collection response. Can be
|
|
246
|
+
combined with --pages. Defaults to one page.
|
|
247
|
+
--no-assets-urls Disables the opening of href links when
|
|
248
|
+
validating assets (enabled by default).
|
|
249
|
+
--header <TEXT TEXT>... HTTP header to include in the requests. Can
|
|
250
|
+
be used multiple times.
|
|
251
|
+
-p, --pages INTEGER Maximum number of pages to validate via
|
|
252
|
+
--item-collection. Defaults to one page.
|
|
253
|
+
-t, --trace-recursion Enables verbose output for recursive mode.
|
|
254
|
+
--no_output Do not print output to console.
|
|
255
|
+
--log_file TEXT Save full recursive output to log file
|
|
256
|
+
(local filepath).
|
|
257
|
+
--pydantic Validate using stac-pydantic models for
|
|
258
|
+
enhanced type checking and validation.
|
|
259
|
+
--verbose Enable verbose output. This will output
|
|
260
|
+
additional information during validation.
|
|
261
|
+
--schema-cache-size INTEGER Max number of schema entries to cache in
|
|
262
|
+
memory. Use 0 to disable schema caching.
|
|
263
|
+
Defaults to 16.
|
|
264
|
+
--help Show this message and exit.
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Batch Command**
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
$ stac-validator batch --help
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
Usage: stac-validator batch [OPTIONS] FILES...
|
|
275
|
+
|
|
276
|
+
Validate multiple STAC files concurrently using all available CPU cores.
|
|
277
|
+
|
|
278
|
+
This command uses multiprocessing to validate STAC files in parallel,
|
|
279
|
+
bypassing Python's Global Interpreter Lock (GIL) for maximum performance.
|
|
280
|
+
Each CPU core gets its own schema cache, which is warmed up on the first
|
|
281
|
+
file and reused for subsequent files.
|
|
282
|
+
|
|
283
|
+
Examples:
|
|
284
|
+
|
|
285
|
+
# Validate all JSON files in a directory
|
|
286
|
+
$ stac-validator batch *.json
|
|
287
|
+
|
|
288
|
+
# Validate specific files
|
|
289
|
+
$ stac-validator batch file1.json file2.json file3.json
|
|
290
|
+
|
|
291
|
+
# Validate a GeoJSON FeatureCollection (validates each feature individually)
|
|
292
|
+
$ stac-validator batch --item-collection sample_data/sentinel-cogs_0_100.json
|
|
293
|
+
|
|
294
|
+
# Use only 4 cores
|
|
295
|
+
$ stac-validator batch *.json --cores 4
|
|
296
|
+
|
|
297
|
+
# Disable progress bar
|
|
298
|
+
$ stac-validator batch *.json --no-progress
|
|
299
|
+
|
|
300
|
+
Options:
|
|
301
|
+
--cores INTEGER Number of CPU cores to use for parallel validation.
|
|
302
|
+
Defaults to all available cores.
|
|
303
|
+
--no-progress Disable progress bar during validation.
|
|
304
|
+
--no-output Do not print output to console.
|
|
305
|
+
--item-collection Treat files as GeoJSON FeatureCollections and validate
|
|
306
|
+
each feature individually.
|
|
307
|
+
--verbose Show full JSON output for all items. By default, only
|
|
308
|
+
invalid items are shown.
|
|
309
|
+
--schema-cache-size INTEGER Max number of schema entries to cache
|
|
310
|
+
per worker process. Use 0 to disable
|
|
311
|
+
schema caching. Defaults to 16.
|
|
312
|
+
--batch-size INTEGER Batch size for chunked processing. Larger
|
|
313
|
+
batches use more memory but may be faster.
|
|
314
|
+
Defaults to 2000.
|
|
315
|
+
--help Show this message and exit.
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Fast Command**
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
$ stac-valid fast --help
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
Usage: stac-valid fast [OPTIONS] STAC_FILE
|
|
326
|
+
|
|
327
|
+
High-speed validation using fastjsonschema and local caching.
|
|
328
|
+
|
|
329
|
+
Options:
|
|
330
|
+
-q, --quiet Suppress individual item logs.
|
|
331
|
+
-v, --verbose Show full validation logs for all items. By default, only
|
|
332
|
+
invalid items are shown.
|
|
333
|
+
--help Show this message and exit.
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
#### Legacy Validation
|
|
337
|
+
|
|
338
|
+
The `validate` command is the main legacy validation tool with comprehensive options:
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
# Basic single file validation
|
|
342
|
+
$ stac-validator validate path/to/stac_file.json
|
|
343
|
+
|
|
344
|
+
# Validate with custom schema
|
|
345
|
+
$ stac-validator validate item.json --custom /path/to/schema.json
|
|
346
|
+
|
|
347
|
+
# Recursively validate all related STAC objects
|
|
348
|
+
$ stac-validator validate catalog.json --recursive --max-depth 5
|
|
349
|
+
|
|
350
|
+
# Validate collections endpoint response
|
|
351
|
+
$ stac-validator validate https://example.com/collections --collections
|
|
352
|
+
|
|
353
|
+
# Validate item collection response
|
|
354
|
+
$ stac-validator validate https://example.com/search --item-collection --pages 10
|
|
355
|
+
|
|
356
|
+
# Validate with extensions and links
|
|
357
|
+
$ stac-validator validate item.json --extensions --links --assets
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
**Options include:**
|
|
361
|
+
- `--core` - Validate core STAC only (skip extensions)
|
|
362
|
+
- `--extensions` - Validate extensions only
|
|
363
|
+
- `--links` - Validate link objects
|
|
364
|
+
- `--assets` - Validate asset objects
|
|
365
|
+
- `--recursive` - Recursively validate related STAC objects
|
|
366
|
+
- `--custom` - Validate against custom schema
|
|
367
|
+
- `--schema-map` - Replace schema URLs during validation
|
|
368
|
+
- `--collections` - Validate /collections endpoint response
|
|
369
|
+
- `--item-collection` - Validate item collection responses
|
|
370
|
+
- `--pydantic` - Use Pydantic models for validation
|
|
371
|
+
- `--schema-cache-size` - Configure schema cache size
|
|
372
|
+
- `--batch-size` - Configure batch size for chunked processing (batch command only)
|
|
373
|
+
- And more (see `stac-validator validate --help`)
|
|
374
|
+
|
|
375
|
+
#### Batch Validation
|
|
376
|
+
|
|
377
|
+
The `batch` command validates multiple STAC files concurrently using multiprocessing to bypass Python's Global Interpreter Lock (GIL). This enables **10-100x performance improvement** over single-threaded validation by utilizing all available CPU cores.
|
|
378
|
+
|
|
379
|
+
**Architecture:**
|
|
380
|
+
|
|
381
|
+
- **Multiprocessing:** Each CPU core runs an independent Python process
|
|
382
|
+
- **Per-worker schema cache:** Each worker maintains its own LRU cache of downloaded schemas (default 16 per worker)
|
|
383
|
+
- **Cache warmup:** First file on each worker downloads schemas, subsequent files use cached copies
|
|
384
|
+
- **Configurable cache:** Use `--schema-cache-size` to adjust cache size per worker (0 = disabled)
|
|
385
|
+
- **Linear scaling:** Performance scales linearly with available cores (e.g., 8 cores = ~8x faster)
|
|
386
|
+
- **Container-aware:** Automatically detects Docker/ECS CPU limits via `os.sched_getaffinity()`
|
|
387
|
+
|
|
388
|
+
**Basic Usage**
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
# Validate all JSON files in current directory
|
|
392
|
+
$ stac-validator batch *.json
|
|
393
|
+
|
|
394
|
+
# Validate specific files
|
|
395
|
+
$ stac-validator batch item1.json item2.json item3.json
|
|
396
|
+
|
|
397
|
+
# Validate a FeatureCollection (extracts and validates each feature)
|
|
398
|
+
$ stac-validator batch collection.json --item-collection
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Options**
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
# Use specific number of cores
|
|
405
|
+
$ stac-validator batch *.json --cores 4
|
|
406
|
+
|
|
407
|
+
# Reserve cores for OS (useful on local machines)
|
|
408
|
+
$ stac-validator batch *.json --cores -1 # Uses all cores minus 1
|
|
409
|
+
|
|
410
|
+
# Disable progress bar (for CI/CD environments)
|
|
411
|
+
$ stac-validator batch *.json --no-progress
|
|
412
|
+
|
|
413
|
+
# Suppress JSON output (show only summary)
|
|
414
|
+
$ stac-validator batch *.json --no-output
|
|
415
|
+
|
|
416
|
+
# Configure schema cache size per worker (default: 16 schemas per worker)
|
|
417
|
+
$ stac-validator batch *.json --schema-cache-size 32
|
|
418
|
+
|
|
419
|
+
# Disable schema caching entirely
|
|
420
|
+
$ stac-validator batch *.json --schema-cache-size 0
|
|
421
|
+
|
|
422
|
+
# Configure batch size for chunked processing (default: 2000 items per chunk)
|
|
423
|
+
$ stac-validator batch *.json --batch-size 5000
|
|
424
|
+
|
|
425
|
+
# Use larger batch size for faster processing (uses more memory)
|
|
426
|
+
$ stac-validator batch collection.json --item-collection --batch-size 10000
|
|
427
|
+
|
|
428
|
+
# Use smaller batch size for memory-constrained environments
|
|
429
|
+
$ stac-validator batch *.json --batch-size 500
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Batch Size Configuration**
|
|
433
|
+
|
|
434
|
+
The `--batch-size` option controls how many items are processed in each chunk. This affects memory usage and performance:
|
|
435
|
+
|
|
436
|
+
- **Default (2000):** Balanced memory usage and performance for most systems
|
|
437
|
+
- **Larger values (5000-10000):** Faster processing on systems with abundant memory; reduces overhead from creating multiple worker pools
|
|
438
|
+
- **Smaller values (500-1000):** Lower memory footprint; useful on memory-constrained systems or when validating very large items
|
|
439
|
+
|
|
440
|
+
**How It Works**
|
|
441
|
+
|
|
442
|
+
1. **Startup:** Detects available CPU cores (respects Docker limits)
|
|
443
|
+
2. **Distribution:** Distributes files across worker processes
|
|
444
|
+
3. **Validation:** Each worker validates files independently
|
|
445
|
+
4. **Schema Caching:** Each worker maintains its own LRU cache (default 16 schemas per worker)
|
|
446
|
+
- First file on a worker: schemas are fetched and cached
|
|
447
|
+
- Subsequent files: schemas are reused from cache (no network/disk I/O)
|
|
448
|
+
- Total memory: up to `cores × schema_cache_size` schemas in memory
|
|
449
|
+
5. **Results:** Aggregates results and displays summary statistics
|
|
450
|
+
|
|
451
|
+
**Example Output**
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
$ stac-validator batch --item-collection sample_data/sentinel-cogs_0_100.json
|
|
455
|
+
[
|
|
456
|
+
{
|
|
457
|
+
"path": "sample_data/sentinel-cogs_0_100.json[0]",
|
|
458
|
+
"valid_stac": false,
|
|
459
|
+
"errors": [
|
|
460
|
+
"'eo:bands' does not match any of the regexes: '^(?!eo:)'. Error is in properties "
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
]
|
|
464
|
+
|
|
465
|
+
Validation Summary:
|
|
466
|
+
Total files: 100
|
|
467
|
+
CPU cores used: 16
|
|
468
|
+
✅ Valid: 99
|
|
469
|
+
❌ Invalid: 1
|
|
470
|
+
|
|
471
|
+
Failed validations:
|
|
472
|
+
sample_data/sentinel-cogs_0_100.json[0]
|
|
473
|
+
- 'eo:bands' does not match any of the regexes: '^(?!eo:)'. Error is in properties
|
|
474
|
+
|
|
475
|
+
Validation completed in 1.10s
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**Performance Characteristics**
|
|
479
|
+
|
|
480
|
+
| Scenario | Single-threaded | Batch (8 cores) | Speedup |
|
|
481
|
+
|----------|-----------------|-----------------|---------|
|
|
482
|
+
| 10000 items | ~130 seconds | ~22 seconds | 5.9x |
|
|
483
|
+
|
|
484
|
+
*Times vary based on schema complexity and network latency for first download*
|
|
485
|
+
|
|
486
|
+
**Python API**
|
|
487
|
+
|
|
488
|
+
```python
|
|
489
|
+
from stac_validator.batch_validator import validate_concurrently
|
|
490
|
+
|
|
491
|
+
# Validate files
|
|
492
|
+
results = validate_concurrently(
|
|
493
|
+
["item1.json", "item2.json", "item3.json"],
|
|
494
|
+
max_workers=None, # Auto-detect cores
|
|
495
|
+
show_progress=True
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
# Validate FeatureCollections
|
|
499
|
+
results = validate_concurrently(
|
|
500
|
+
["collection.json"],
|
|
501
|
+
feature_collection=True,
|
|
502
|
+
max_workers=8
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
# Process results
|
|
506
|
+
for result in results:
|
|
507
|
+
if result["valid_stac"]:
|
|
508
|
+
print(f"✅ {result['path']}")
|
|
509
|
+
else:
|
|
510
|
+
print(f"❌ {result['path']}")
|
|
511
|
+
for error in result.get("errors", []):
|
|
512
|
+
print(f" - {error}")
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Use Cases**
|
|
516
|
+
|
|
517
|
+
- **Bulk ingestion:** Validate thousands of STAC items from ESA, Copernicus, or other catalogs
|
|
518
|
+
- **CI/CD pipelines:** Validate entire dataset collections in GitHub Actions or AWS CodePipeline
|
|
519
|
+
- **Data quality checks:** Periodically validate all items in a STAC catalog
|
|
520
|
+
- **Migration validation:** Verify all items when upgrading STAC versions
|
|
521
|
+
- **API preprocessing:** Validate incoming FeatureCollections before storage (see FastAPI integration)
|
|
522
|
+
|
|
523
|
+
#### Fast Validation
|
|
524
|
+
|
|
525
|
+
The `fast` command provides ultra-high-speed validation using `fastjsonschema` with intelligent caching. It's optimized for large FeatureCollections, delivering **batch-like performance with significantly lower memory overhead** by using a single-threaded, compiled validator approach instead of multiprocessing.
|
|
526
|
+
|
|
527
|
+
**Key Features:**
|
|
528
|
+
|
|
529
|
+
- **fastjsonschema:** Compiled validators for 10-100x faster validation than standard jsonschema
|
|
530
|
+
- **Single-threaded:** No multiprocessing overhead - ideal for memory-constrained environments
|
|
531
|
+
- **Batch-comparable speed:** Similar throughput to batch command but with minimal memory footprint
|
|
532
|
+
- **Multi-tier caching:** RAM → Disk → Network with automatic fallback
|
|
533
|
+
- **Local schema storage:** Schemas cached locally under `local_schemas/.schemas` directory for instant reuse
|
|
534
|
+
- **Automatic detection:** Detects STAC type (Item, Collection, Catalog, FeatureCollection) automatically
|
|
535
|
+
- **Detailed metrics:** Shows setup time, execution time, and cache hit status for each item
|
|
536
|
+
- **Error grouping:** Groups validation errors by type and shows affected items
|
|
537
|
+
|
|
538
|
+
**Basic Usage**
|
|
539
|
+
|
|
540
|
+
```bash
|
|
541
|
+
# Validate a single STAC Item
|
|
542
|
+
$ stac-validator fast item.json
|
|
543
|
+
|
|
544
|
+
# Validate a FeatureCollection (validates each feature)
|
|
545
|
+
$ stac-validator fast collection.json
|
|
546
|
+
|
|
547
|
+
# Validate a STAC Collection
|
|
548
|
+
$ stac-validator fast collection-metadata.json
|
|
549
|
+
|
|
550
|
+
# Validate a STAC Catalog
|
|
551
|
+
$ stac-validator fast catalog.json
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**Options**
|
|
555
|
+
|
|
556
|
+
```bash
|
|
557
|
+
# Suppress output (only show summary)
|
|
558
|
+
$ stac-validator fast item.json --quiet
|
|
559
|
+
|
|
560
|
+
# Show detailed output for all items (default shows first 5)
|
|
561
|
+
$ stac-validator fast collection.json --verbose
|
|
562
|
+
|
|
563
|
+
# Combine options
|
|
564
|
+
$ stac-validator fast collection.json --verbose --quiet # Quiet takes precedence
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
**Example Output**
|
|
568
|
+
|
|
569
|
+
```bash
|
|
570
|
+
$ stac-validator fast sample_data/sentinel-cogs_0_100.json
|
|
571
|
+
|
|
572
|
+
📂 Loading: sample_data/sentinel-cogs_0_100.json
|
|
573
|
+
📦 Detected FeatureCollection (100 Items)
|
|
574
|
+
|
|
575
|
+
[1] ID: S2B_1CDH_20191211_0_L2A | Type: Item | Cache 🐌 | Setup: 125.34ms | Exec: 2.45ms | ✅ VALID
|
|
576
|
+
[2] ID: S2B_1CDH_20191220_0_L2A | Type: Item | Cache ⚡ | Setup: 0.12ms | Exec: 1.89ms | ✅ VALID
|
|
577
|
+
[3] ID: S2B_1CDH_20191230_0_L2A | Type: Item | Cache ⚡ | Setup: 0.08ms | Exec: 2.12ms | ❌ INVALID
|
|
578
|
+
[4] ID: S2B_1CCV_20191029_0_L2A | Type: Item | Cache ⚡ | Setup: 0.09ms | Exec: 1.95ms | ✅ VALID
|
|
579
|
+
[5] ID: S2B_1CCV_20191128_0_L2A | Type: Item | Cache ⚡ | Setup: 0.07ms | Exec: 2.03ms | ✅ VALID
|
|
580
|
+
... silencing output for remaining items (validating at maximum speed) ...
|
|
581
|
+
|
|
582
|
+
=======================================================
|
|
583
|
+
📊 VALIDATION SUMMARY
|
|
584
|
+
=======================================================
|
|
585
|
+
Total Objects Processed : 100
|
|
586
|
+
Valid Objects : 46
|
|
587
|
+
Invalid Objects : 54
|
|
588
|
+
-------------------------------------------------------
|
|
589
|
+
Total Setup Time : 144.35 ms
|
|
590
|
+
Total Execution Time : 25.74 ms
|
|
591
|
+
Average Exec per Object : 0.257 ms
|
|
592
|
+
=======================================================
|
|
593
|
+
🚨 ERROR BREAKDOWN
|
|
594
|
+
=======================================================
|
|
595
|
+
|
|
596
|
+
❌ STAC Spec Violation: Missing {'rel': 'collection'} in links array.
|
|
597
|
+
Affected Items: 54
|
|
598
|
+
Examples: S2B_1CCV_20190102_0_L2A, S2B_1CCV_20190122_0_L2A, S2B_1CCV_20191029_0_L2A ... (and 51 more)
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
**Cache Indicators**
|
|
602
|
+
|
|
603
|
+
- **🐌 (Slow):** First validation - schemas being fetched and compiled
|
|
604
|
+
- **⚡ (Lightning):** Cached validator - instant execution using pre-compiled validator
|
|
605
|
+
|
|
606
|
+
**Schema Caching & Performance Improvement**
|
|
607
|
+
|
|
608
|
+
The fast validator uses a multi-tier caching strategy that dramatically speeds up subsequent runs:
|
|
609
|
+
|
|
610
|
+
1. **First Run:** Schemas are downloaded from the network and compiled with `fastjsonschema`
|
|
611
|
+
- Setup time: 5-6 seconds (includes network fetch for all schemas + compilation)
|
|
612
|
+
- Per-item execution: 0.25ms
|
|
613
|
+
- Total for 100 items: ~5.4 seconds
|
|
614
|
+
- Total for 1000 items: ~10-11 seconds
|
|
615
|
+
|
|
616
|
+
2. **Subsequent Runs:** Schemas are loaded from local disk cache (`.schemas/` directory)
|
|
617
|
+
- Setup time: 100-200ms (instant disk read + compilation from cache)
|
|
618
|
+
- Per-item execution: 0.25ms
|
|
619
|
+
- Total for 100 items: ~150-200ms
|
|
620
|
+
- Total for 1000 items: ~400-500ms (0.4-0.5 seconds)
|
|
621
|
+
- **Speedup: 20-25x faster** compared to first run
|
|
622
|
+
|
|
623
|
+
**Cache Storage:**
|
|
624
|
+
|
|
625
|
+
Schemas are automatically cached in `local_schemas/.schemas/` directory:
|
|
626
|
+
```
|
|
627
|
+
local_schemas/
|
|
628
|
+
└── .schemas/
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
This means:
|
|
632
|
+
- ✅ No network calls on subsequent validations
|
|
633
|
+
- ✅ Instant schema availability across multiple runs
|
|
634
|
+
- ✅ Persistent cache survives process restarts
|
|
635
|
+
- ✅ Minimal disk space usage (schemas are typically <100KB each)
|
|
636
|
+
|
|
637
|
+
**Performance Characteristics**
|
|
638
|
+
|
|
639
|
+
The fast validator is optimized for:
|
|
640
|
+
- Large FeatureCollections (100-100,000+ items)
|
|
641
|
+
- Memory-constrained environments (single-threaded, no multiprocessing)
|
|
642
|
+
- Rapid iteration during development
|
|
643
|
+
- CI/CD pipelines where speed and memory efficiency are critical
|
|
644
|
+
|
|
645
|
+
Typical performance (subsequent runs with disk cache):
|
|
646
|
+
- **Setup time:** 100-200ms (disk read + compilation from cached schemas)
|
|
647
|
+
- **Per-item execution:** 0.23-0.25ms (compiled fastjsonschema validator)
|
|
648
|
+
- **Total time for 100 items:** ~150-200ms
|
|
649
|
+
- **Total time for 1000 items:** ~400-500ms (0.4-0.5 seconds)
|
|
650
|
+
- **Memory footprint:** Single process, minimal overhead (vs. batch's multiprocessing overhead)
|
|
651
|
+
|
|
652
|
+
**Batch vs. Fast Comparison**
|
|
653
|
+
|
|
654
|
+
| Metric | Batch | Fast |
|
|
655
|
+
|--------|-------|------|
|
|
656
|
+
| Memory | High (multiprocessing) | Low (single-threaded) |
|
|
657
|
+
| CPU cores | All available | Single core |
|
|
658
|
+
| Best for | Large systems with many cores | Memory-constrained or single-core systems |
|
|
659
|
+
| FeatureCollections | Excellent | Excellent |
|
|
660
|
+
| Large datasets | Excellent | Good |
|
|
661
|
+
|
|
662
|
+
**Python API**
|
|
663
|
+
|
|
664
|
+
```python
|
|
665
|
+
from stac_validator.fast_validator import FastValidator
|
|
666
|
+
|
|
667
|
+
# Validate a file
|
|
668
|
+
validator = FastValidator("item.json", quiet=False, verbose=False)
|
|
669
|
+
validator.run()
|
|
670
|
+
|
|
671
|
+
# Check if valid
|
|
672
|
+
if validator.valid:
|
|
673
|
+
print("✅ Valid STAC")
|
|
674
|
+
else:
|
|
675
|
+
print("❌ Invalid STAC")
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
**Choosing the Right Command**
|
|
679
|
+
|
|
680
|
+
| Use Case | Command | Why |
|
|
681
|
+
|----------|---------|-----|
|
|
682
|
+
| Single file validation | `validate` | Full feature set, detailed error messages, extensions support |
|
|
683
|
+
| Large FeatureCollections (memory-constrained) | `fast` | Batch-like speed, single-threaded, minimal memory overhead |
|
|
684
|
+
| Bulk validation (1000+ files, multi-core systems) | `batch` | Multiprocessing, utilizes all CPU cores, scales linearly |
|
|
685
|
+
| Quick validation with detailed metrics | `fast` | Ultra-fast with fastjsonschema, timing info per item, auto-detection |
|
|
686
|
+
| CI/CD pipelines (memory-limited) | `fast` | Fast, low memory, suitable for containers and serverless |
|
|
687
|
+
| CI/CD pipelines (resource-rich) | `batch` | Parallelization, maximum throughput, consistent output |
|
|
688
|
+
| Development/testing | `fast` | Instant feedback, detailed metrics, minimal overhead |
|
|
689
|
+
| Complex validation rules | `validate` | Full control over validation options, recursive validation |
|
|
690
|
+
|
|
691
|
+
### Python
|
|
692
|
+
|
|
693
|
+
**Single File Validation**
|
|
694
|
+
|
|
695
|
+
```python
|
|
696
|
+
from stac_validator import stac_validator
|
|
697
|
+
|
|
698
|
+
# Remote source
|
|
699
|
+
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")
|
|
700
|
+
stac.run()
|
|
701
|
+
print(stac.message)
|
|
702
|
+
|
|
703
|
+
# Local file
|
|
704
|
+
stac = stac_validator.StacValidate("tests/test_data/1beta1/sentinel2.json", extensions=True)
|
|
705
|
+
stac.run()
|
|
706
|
+
print(stac.message)
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
**Dictionary Validation**
|
|
710
|
+
|
|
711
|
+
```python
|
|
712
|
+
from stac_validator import stac_validator
|
|
713
|
+
|
|
714
|
+
stac = stac_validator.StacValidate()
|
|
715
|
+
stac.validate_dict(item_dict)
|
|
716
|
+
print(stac.message)
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
**Batch Validation - List of Dictionaries**
|
|
720
|
+
|
|
721
|
+
For validating dictionaries directly without managing temp files, use `validate_dicts()`:
|
|
722
|
+
|
|
723
|
+
```python
|
|
724
|
+
from stac_validator.batch_validator import validate_dicts
|
|
725
|
+
|
|
726
|
+
items = [
|
|
727
|
+
{"type": "Feature", "stac_version": "1.1.0", ...},
|
|
728
|
+
{"type": "Feature", "stac_version": "1.1.0", ...},
|
|
729
|
+
{"type": "Feature", "stac_version": "1.1.0", ...},
|
|
730
|
+
]
|
|
731
|
+
|
|
732
|
+
# Validate all items concurrently (temp files handled internally)
|
|
733
|
+
results = validate_dicts(items, max_workers=None, show_progress=True)
|
|
734
|
+
|
|
735
|
+
print(f"Total: {len(results)}")
|
|
736
|
+
print(f"Valid: {sum(1 for r in results if r['valid_stac'])}")
|
|
737
|
+
print(f"Invalid: {sum(1 for r in results if not r['valid_stac'])}")
|
|
738
|
+
|
|
739
|
+
# Process results
|
|
740
|
+
for result in results:
|
|
741
|
+
if result["valid_stac"]:
|
|
742
|
+
print(f"✅ Valid")
|
|
743
|
+
else:
|
|
744
|
+
print(f"❌ Invalid: {result.get('errors', [])}")
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
**Parameters:**
|
|
748
|
+
- `items` - List of STAC item dictionaries
|
|
749
|
+
- `max_workers` - CPU cores to use (None = auto-detect, positive int = specific cores, negative int = all minus N)
|
|
750
|
+
- `show_progress` - Display progress bar (default: True)
|
|
751
|
+
- `chunk_size` - Number of items to process at a time to bound disk and memory usage (default: 1000)
|
|
752
|
+
|
|
753
|
+
**Batch Validation - FeatureCollection (Concurrent with Multiprocessing)**
|
|
754
|
+
|
|
755
|
+
For FeatureCollection validation with multiprocessing, use `validate_concurrently()` with `feature_collection=True`:
|
|
756
|
+
|
|
757
|
+
```python
|
|
758
|
+
from stac_validator.batch_validator import validate_concurrently
|
|
759
|
+
|
|
760
|
+
# Validate FeatureCollection files directly (10-100x faster for large collections)
|
|
761
|
+
results = validate_concurrently(
|
|
762
|
+
["collection1.json", "collection2.json"],
|
|
763
|
+
feature_collection=True, # Expand and validate each feature
|
|
764
|
+
max_workers=None # Auto-detect cores
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
print(f"Total features: {len(results)}")
|
|
768
|
+
print(f"Valid: {sum(1 for r in results if r['valid_stac'])}")
|
|
769
|
+
print(f"Invalid: {sum(1 for r in results if not r['valid_stac'])}")
|
|
770
|
+
|
|
771
|
+
# Process results
|
|
772
|
+
for result in results:
|
|
773
|
+
if result["valid_stac"]:
|
|
774
|
+
print(f"✅ Feature valid")
|
|
775
|
+
else:
|
|
776
|
+
print(f"❌ Feature invalid: {result.get('errors', [])}")
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Batch Validation - Multiple Files**
|
|
780
|
+
|
|
781
|
+
```python
|
|
782
|
+
from stac_validator.batch_validator import validate_concurrently
|
|
783
|
+
|
|
784
|
+
files = [
|
|
785
|
+
"item1.json",
|
|
786
|
+
"item2.json",
|
|
787
|
+
"item3.json",
|
|
788
|
+
]
|
|
789
|
+
|
|
790
|
+
# Validate files concurrently using all available CPU cores
|
|
791
|
+
results = validate_concurrently(
|
|
792
|
+
files,
|
|
793
|
+
max_workers=None, # Auto-detect cores
|
|
794
|
+
show_progress=True
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
# Process results
|
|
798
|
+
for result in results:
|
|
799
|
+
if result["valid_stac"]:
|
|
800
|
+
print(f"✅ {result['path']}")
|
|
801
|
+
else:
|
|
802
|
+
print(f"❌ {result['path']}: {result.get('errors', [])}")
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
**Batch Validation - FeatureCollection Files**
|
|
806
|
+
|
|
807
|
+
```python
|
|
808
|
+
from stac_validator.batch_validator import validate_concurrently
|
|
809
|
+
|
|
810
|
+
files = ["collection1.json", "collection2.json"]
|
|
811
|
+
|
|
812
|
+
# Validate FeatureCollections by extracting and validating each feature
|
|
813
|
+
results = validate_concurrently(
|
|
814
|
+
files,
|
|
815
|
+
feature_collection=True,
|
|
816
|
+
max_workers=8
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
# Results show feature index: "collection1.json[0]", "collection1.json[1]", etc.
|
|
820
|
+
for result in results:
|
|
821
|
+
print(f"{result['path']}: {'✅' if result['valid_stac'] else '❌'}")
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
**Item Collection Validation**
|
|
825
|
+
|
|
826
|
+
```python
|
|
827
|
+
from stac_validator import stac_validator
|
|
828
|
+
|
|
829
|
+
stac = stac_validator.StacValidate()
|
|
830
|
+
stac.validate_item_collection_dict(item_collection_dict)
|
|
831
|
+
print(stac.message)
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
**Configure Schema Cache Size**
|
|
835
|
+
|
|
836
|
+
```python
|
|
837
|
+
from stac_validator import stac_validator
|
|
838
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
839
|
+
|
|
840
|
+
# Set once at app startup (process-wide)
|
|
841
|
+
set_schema_cache_size(16) # use 0 to disable caching
|
|
842
|
+
|
|
843
|
+
stac = stac_validator.StacValidate()
|
|
844
|
+
stac.validate_dict(dictionary)
|
|
845
|
+
print(stac.message)
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
### Schema Cache Settings
|
|
850
|
+
|
|
851
|
+
- Default schema cache size is 16 entries.
|
|
852
|
+
- Use `--schema-cache-size` in the CLI or `set_schema_cache_size(...)` in Python to override it.
|
|
853
|
+
- Use `0` to disable schema caching.
|
|
854
|
+
|
|
855
|
+
Use `set_schema_cache_size` once at application startup:
|
|
856
|
+
|
|
857
|
+
```python
|
|
858
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
859
|
+
|
|
860
|
+
# Examples:
|
|
861
|
+
set_schema_cache_size(16) # small cache for low-memory deployments
|
|
862
|
+
set_schema_cache_size(64) # moderate cache for long-running services
|
|
863
|
+
set_schema_cache_size(0) # disable schema caching
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
Notes:
|
|
867
|
+
- `StacValidate()` and `validate_dict()` do not accept a cache-size parameter.
|
|
868
|
+
- Changing cache size at runtime replaces the cache instance and drops existing cached entries.
|
|
869
|
+
- In multi-worker deployments, configure cache size in each worker process.
|
|
870
|
+
|
|
871
|
+
## Performance Benchmarking
|
|
872
|
+
|
|
873
|
+
A benchmark script is included to compare the performance of batch validation vs legacy item-collection validation. This is useful for understanding the performance improvements of the multiprocessing batch validator.
|
|
874
|
+
|
|
875
|
+
### Running the Benchmark
|
|
876
|
+
|
|
877
|
+
```bash
|
|
878
|
+
# Test with 10,000 items (default)
|
|
879
|
+
python benchmark_validation.py
|
|
880
|
+
|
|
881
|
+
# Test with custom number of items
|
|
882
|
+
python benchmark_validation.py --items 5000
|
|
883
|
+
python benchmark_validation.py --items 50000
|
|
884
|
+
|
|
885
|
+
# Run only batch validation (skip slow legacy validation)
|
|
886
|
+
python benchmark_validation.py --items 10000 --batch-only
|
|
887
|
+
|
|
888
|
+
# Run only legacy validation
|
|
889
|
+
python benchmark_validation.py --items 10000 --legacy-only
|
|
890
|
+
|
|
891
|
+
# View all options
|
|
892
|
+
python benchmark_validation.py --help
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
### Example Output
|
|
896
|
+
|
|
897
|
+
```
|
|
898
|
+
======================================================================
|
|
899
|
+
BENCHMARK RESULTS
|
|
900
|
+
======================================================================
|
|
901
|
+
Items tested: 10000
|
|
902
|
+
|
|
903
|
+
Batch Validation (multiprocessing):
|
|
904
|
+
Time: 22.43s
|
|
905
|
+
✅ Valid: 0
|
|
906
|
+
❌ Invalid: 10000
|
|
907
|
+
|
|
908
|
+
Legacy Validation (single-threaded):
|
|
909
|
+
Time: 131.62s
|
|
910
|
+
✅ Valid: 0
|
|
911
|
+
❌ Invalid: 10000
|
|
912
|
+
|
|
913
|
+
======================================================================
|
|
914
|
+
Speedup: 5.9x faster with batch validation
|
|
915
|
+
Time saved: 109.19s
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
### Interpreting Results
|
|
919
|
+
|
|
920
|
+
- **Speedup Factor**: Shows how many times faster batch validation is compared to legacy validation
|
|
921
|
+
- **Time Saved**: The absolute time difference in seconds
|
|
922
|
+
- **CPU Cores Used**: Number of CPU cores utilized by batch validation (typically all available cores)
|
|
923
|
+
|
|
924
|
+
The batch validator's multiprocessing approach provides significant performance improvements, especially for large datasets. The speedup factor varies based on:
|
|
925
|
+
- Number of CPU cores available
|
|
926
|
+
- Size of the dataset
|
|
927
|
+
- Complexity of validation (extensions, custom schemas, etc.)
|
|
928
|
+
|
|
929
|
+
## Deployment
|
|
930
|
+
|
|
931
|
+
### Docker
|
|
932
|
+
|
|
933
|
+
The validator can run using docker containers.
|
|
934
|
+
|
|
935
|
+
```bash
|
|
936
|
+
$ docker build -t stac-validator .
|
|
937
|
+
$ docker run stac-validator https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json
|
|
938
|
+
```
|
|
939
|
+
|
|
940
|
+
```bash
|
|
941
|
+
[
|
|
942
|
+
{
|
|
943
|
+
"version": "1.0.0",
|
|
944
|
+
"path": "https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json",
|
|
945
|
+
"schema": [
|
|
946
|
+
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
|
|
947
|
+
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
|
|
948
|
+
],
|
|
949
|
+
"valid_stac": true,
|
|
950
|
+
"asset_type": "ITEM",
|
|
951
|
+
"validation_method": "default"
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
### AWS (CDK)
|
|
957
|
+
|
|
958
|
+
An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
|
|
959
|
+
|
|
960
|
+
```bash
|
|
961
|
+
$ cd cdk-deployment
|
|
962
|
+
$ cdk diff
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
## Testing
|
|
966
|
+
|
|
967
|
+
```bash
|
|
968
|
+
$ make test
|
|
969
|
+
# or
|
|
970
|
+
$ pytest -v
|
|
971
|
+
```
|
|
972
|
+
|
|
973
|
+
See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
|
|
974
|
+
|
|
975
|
+
## Additional Examples
|
|
976
|
+
|
|
977
|
+
### --core
|
|
978
|
+
|
|
979
|
+
```bash
|
|
980
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --core
|
|
981
|
+
```
|
|
982
|
+
|
|
983
|
+
```bash
|
|
984
|
+
[
|
|
985
|
+
{
|
|
986
|
+
"version": "1.0.0",
|
|
987
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
|
|
988
|
+
"schema": [
|
|
989
|
+
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
|
|
990
|
+
],
|
|
991
|
+
"valid_stac": true,
|
|
992
|
+
"asset_type": "ITEM",
|
|
993
|
+
"validation_method": "core"
|
|
994
|
+
}
|
|
995
|
+
]
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
### --custom
|
|
999
|
+
|
|
1000
|
+
```bash
|
|
1001
|
+
$ stac-validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json
|
|
1002
|
+
```
|
|
1003
|
+
|
|
1004
|
+
```bash
|
|
1005
|
+
[
|
|
1006
|
+
{
|
|
1007
|
+
"version": "0.7.0",
|
|
1008
|
+
"path": "https://radarstac.s3.amazonaws.com/stac/catalog.json",
|
|
1009
|
+
"schema": [
|
|
1010
|
+
"https://cdn.staclint.com/v0.7.0/catalog.json"
|
|
1011
|
+
],
|
|
1012
|
+
"asset_type": "CATALOG",
|
|
1013
|
+
"validation_method": "custom",
|
|
1014
|
+
"valid_stac": true
|
|
1015
|
+
}
|
|
1016
|
+
]
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
### --extensions
|
|
1020
|
+
|
|
1021
|
+
```bash
|
|
1022
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
```bash
|
|
1026
|
+
[
|
|
1027
|
+
{
|
|
1028
|
+
"version": "1.0.0",
|
|
1029
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
|
|
1030
|
+
"schema": [
|
|
1031
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
1032
|
+
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
|
|
1033
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
1034
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
1035
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
|
|
1036
|
+
],
|
|
1037
|
+
"valid_stac": true,
|
|
1038
|
+
"asset_type": "ITEM",
|
|
1039
|
+
"validation_method": "extensions"
|
|
1040
|
+
}
|
|
1041
|
+
]
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
### --recursive
|
|
1045
|
+
|
|
1046
|
+
```bash
|
|
1047
|
+
$ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --trace-recursion
|
|
1048
|
+
```
|
|
1049
|
+
|
|
1050
|
+
```bash
|
|
1051
|
+
[
|
|
1052
|
+
{
|
|
1053
|
+
"version": "0.8.1",
|
|
1054
|
+
"path": "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot4_orthoimages/collection.json",
|
|
1055
|
+
"schema": "https://cdn.staclint.com/v0.8.1/collection.json",
|
|
1056
|
+
"asset_type": "COLLECTION",
|
|
1057
|
+
"validation_method": "recursive",
|
|
1058
|
+
"valid_stac": true
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
"version": "0.8.1",
|
|
1062
|
+
"path": "https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/collection.json",
|
|
1063
|
+
"schema": "https://cdn.staclint.com/v0.8.1/collection.json",
|
|
1064
|
+
"asset_type": "COLLECTION",
|
|
1065
|
+
"validation_method": "recursive",
|
|
1066
|
+
"valid_stac": true
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
"version": "0.8.1",
|
|
1070
|
+
"path": "https://spot-canada-ortho.s3.amazonaws.com/catalog.json",
|
|
1071
|
+
"schema": "https://cdn.staclint.com/v0.8.1/catalog.json",
|
|
1072
|
+
"asset_type": "CATALOG",
|
|
1073
|
+
"validation_method": "recursive",
|
|
1074
|
+
"valid_stac": true
|
|
1075
|
+
}
|
|
1076
|
+
]
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
### --item-collection
|
|
1080
|
+
|
|
1081
|
+
```bash
|
|
1082
|
+
$ stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
### --header
|
|
1086
|
+
|
|
1087
|
+
```bash
|
|
1088
|
+
$ stac-validator https://stac-catalog.eu/collections/sentinel-s2-l2a/items --header x-api-key $MY_API_KEY --header foo bar
|
|
1089
|
+
```
|
|
1090
|
+
|
|
1091
|
+
### --schema-map
|
|
1092
|
+
|
|
1093
|
+
Schema map allows stac-validator to replace a schema in a STAC json by a schema from another URL or local schema file.
|
|
1094
|
+
This is especially useful when developing a schema and testing validation against your local copy of the schema.
|
|
1095
|
+
|
|
1096
|
+
```bash
|
|
1097
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --extensions --schema-map https://stac-extensions.github.io/projection/v1.0.0/schema.json "tests/test_data/schema/v1.0.0/projection.json"
|
|
1098
|
+
```
|
|
1099
|
+
|
|
1100
|
+
```bash
|
|
1101
|
+
[
|
|
1102
|
+
{
|
|
1103
|
+
"version": "1.0.0",
|
|
1104
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json",
|
|
1105
|
+
"schema": [
|
|
1106
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
1107
|
+
"tests/test_data/schema/v1.0.0/projection.json",
|
|
1108
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
1109
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
1110
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
|
|
1111
|
+
],
|
|
1112
|
+
"valid_stac": true,
|
|
1113
|
+
"asset_type": "ITEM",
|
|
1114
|
+
"validation_method": "extensions"
|
|
1115
|
+
}
|
|
1116
|
+
]
|
|
1117
|
+
```
|
|
1118
|
+
|
|
1119
|
+
This option is also capable of replacing URLs to subschemas:
|
|
1120
|
+
|
|
1121
|
+
```bash
|
|
1122
|
+
$ stac-validator tests/test_data/v100/extended-item-local.json --custom tests/test_data/schema/v1.0.0/item_with_unreachable_url.json --schema-map https://geojson-wrong-url.org/schema/Feature.json https://geojson.org/schema/Feature.json --schema-map https://geojson-wrong-url.org/schema/Geometry.json https://geojson.org/schema/Geometry.json
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
```bash
|
|
1126
|
+
[
|
|
1127
|
+
{
|
|
1128
|
+
"version": "1.0.0",
|
|
1129
|
+
"path": "tests/test_data/v100/extended-item-local.json",
|
|
1130
|
+
"schema": [
|
|
1131
|
+
"tests/test_data/schema/v1.0.0/item_with_unreachable_url.json"
|
|
1132
|
+
],
|
|
1133
|
+
"valid_stac": true,
|
|
1134
|
+
"asset_type": "ITEM",
|
|
1135
|
+
"validation_method": "custom"
|
|
1136
|
+
}
|
|
1137
|
+
]
|
|
1138
|
+
```
|
|
1139
|
+
|
|
1140
|
+
### --schema-config
|
|
1141
|
+
|
|
1142
|
+
The `--schema-config` option allows you to specify a YAML or JSON configuration file that maps remote schema URLs to local file paths. This is useful when you need to validate against multiple local schemas and want to avoid using multiple `--schema-map` arguments.
|
|
1143
|
+
|
|
1144
|
+
Example schema config file (YAML):
|
|
1145
|
+
```yaml
|
|
1146
|
+
schemas:
|
|
1147
|
+
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json": "local_schemas/v1.0.0/collection.json"
|
|
1148
|
+
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json": "local_schemas/v1.0.0/item.json"
|
|
1149
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json": "local_schemas/v1.0.0/eo.json"
|
|
1150
|
+
```
|
|
1151
|
+
|
|
1152
|
+
Usage:
|
|
1153
|
+
```bash
|
|
1154
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/extended-item.json --schema-config path/to/schema_config.yaml
|
|
1155
|
+
```
|
|
1156
|
+
|
|
1157
|
+
The paths in the config file can be absolute or relative to the config file's location.
|
|
1158
|
+
|
|
1159
|
+
### --pydantic
|
|
1160
|
+
|
|
1161
|
+
The `--pydantic` option provides enhanced validation using stac-pydantic models, which offer stronger type checking and more detailed error messages. To use this feature, you need to install the optional dependency:
|
|
1162
|
+
|
|
1163
|
+
```bash
|
|
1164
|
+
$ pip install stac-valid[pydantic]
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
Then you can validate your STAC objects using Pydantic models:
|
|
1168
|
+
|
|
1169
|
+
```bash
|
|
1170
|
+
$ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --pydantic
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
```bash
|
|
1174
|
+
[
|
|
1175
|
+
{
|
|
1176
|
+
"version": "1.0.0",
|
|
1177
|
+
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
|
|
1178
|
+
"schema": [
|
|
1179
|
+
"stac-pydantic Item model"
|
|
1180
|
+
],
|
|
1181
|
+
"valid_stac": true,
|
|
1182
|
+
"asset_type": "ITEM",
|
|
1183
|
+
"validation_method": "pydantic",
|
|
1184
|
+
"extension_schemas": [
|
|
1185
|
+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
|
|
1186
|
+
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
|
|
1187
|
+
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
|
|
1188
|
+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
|
|
1189
|
+
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json"
|
|
1190
|
+
],
|
|
1191
|
+
"model_validation": "passed"
|
|
1192
|
+
}
|
|
1193
|
+
]
|
|
1194
|
+
```
|
|
1195
|
+
|
|
1196
|
+
## Sponsors and Supporters
|
|
1197
|
+
|
|
1198
|
+
The following organizations have contributed time and/or funding to support the development of this project:
|
|
1199
|
+
- [Healy Hyperspatial](https://healy-hyperspatial.github.io/)
|
|
1200
|
+
- [Radiant Earth Foundation](https://radiant.earth/)
|
|
1201
|
+
- [Sparkgeo](https://sparkgeo.com/)
|
|
1202
|
+
- [CloudFerro](https://cloudferro.com/)
|
|
1203
|
+
|
|
1204
|
+
<p align="left">
|
|
1205
|
+
<a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
|
|
1206
|
+
<a href="https://radiant.earth/"><img src="assets/radiant-earth.webp" alt="Radiant Earth Foundation" height="100" hspace="20"></a>
|
|
1207
|
+
<a href="https://sparkgeo.com/"><img src="assets/sparkgeo_logo.jpeg" alt="Sparkgeo" height="100" hspace="20"></a>
|
|
1208
|
+
<a href="https://cloudferro.com/"><img src="assets/cloudferro-logo.png" alt="CloudFerro" height="110" hspace="20"></a>
|
|
1209
|
+
</p>
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
## Contributing
|
|
1213
|
+
|
|
1214
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
1215
|
+
|
|
1216
|
+
## License
|
|
1217
|
+
|
|
1218
|
+
This project is licensed under the Apache License 2.0.
|