Catalog & utility API#
The shared plumbing every provider backend builds on: catalog loading, the strict YAML parser, the provider registry, and the small filesystem helpers. See Base contracts for the rules these implement.
Catalog loading#
All 48 catalog loaders route through load_catalog, which owns the catalog glob, the (path, mtime_ns) cache
key, and the cache registry.
earthlens.base.load_catalog(path, cache, parse, *, provider, shard_noun='')
#
Return the parsed catalog at path, memoised on the files' mtimes.
The composition every provider loader repeats: resolve the contributing
files, build the key, return a live cache hit, else call parse and store
the result. parse receives the file list and owns everything
provider-specific — the row models, the merge across shards, the
duplicate-key checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The catalog directory or single YAML file. |
required |
cache
|
CatalogParseCache
|
The module's :class: |
required |
parse
|
Callable[[list[Path]], T]
|
Callable taking the contributing files and returning the parsed catalog. Called only on a cache miss. |
required |
provider
|
str
|
Provider name for the not-found error. |
required |
shard_noun
|
str
|
Optional sharding description for that error. |
''
|
Returns:
| Type | Description |
|---|---|
T
|
Whatever |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- The parse runs once, then the cached value is reused:
>>> import tempfile >>> from pathlib import Path >>> from earthlens.base.yaml_loader import CatalogParseCache >>> from earthlens.base.catalog_source import load_catalog >>> one = Path(tempfile.mkdtemp()) / "c.yaml" >>> _ = one.write_text("datasets: {}\n") >>> cache, calls = CatalogParseCache(), [] >>> def parse(files): ... calls.append(files) ... return {"rows": len(files)} >>> load_catalog(one, cache, parse, provider="Demo") {'rows': 1} >>> load_catalog(one, cache, parse, provider="Demo") {'rows': 1} >>> len(calls) 1
Source code in libs/core/src/earthlens/base/catalog_source.py
Strict YAML#
The duplicate-key-rejecting loader every catalog parses through — a mapping that declares the same key twice
raises ValueError rather than silently keeping the last value.
earthlens.base.yaml_loader.load_yaml_strict(path)
#
Parse a YAML file, rejecting duplicate mapping keys.
A thin wrapper over yaml.load(..., Loader=_StrictSafeLoader) so
callers (the catalog loaders) never touch the loader class directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Filesystem path to the YAML file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The parsed YAML (typically a |
Any
|
file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any mapping in the file declares a key twice. |
Examples:
- Parse a small YAML file and read a value:
- A duplicate mapping key is rejected at parse time:
See Also
earthlens.ecmwf.catalog.Catalog: Uses this to load the CDS catalog. earthlens.gee.catalog.Catalog: Uses this to load the GEE catalog.
Source code in libs/core/src/earthlens/base/yaml_loader.py
Provider registry#
Backends that populate the base providers field load it from a per-backend providers.yaml.
earthlens.base.Provider
#
Bases: BaseModel
One canonical data provider — a slug-id with a display name and parent.
Frozen value object loaded from a backend's providers.yaml.
Datasets reference providers by slug via their provider: field;
the catalog loader validates that every referenced slug is
registered.
Attributes:
| Name | Type | Description |
|---|---|---|
slug |
str
|
Stable kebab-case identifier (e.g. |
display_name |
str
|
Human-readable name to render in docs and UIs. |
parent |
str | None
|
Slug of the parent provider, or |
Source code in libs/core/src/earthlens/base/providers.py
earthlens.base.load_providers(path)
#
Parse + cache providers.yaml at path, keyed on (path, mtime_ns).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path of a |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Provider]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file is missing, declares a slug whose
|
Source code in libs/core/src/earthlens/base/providers.py
Filesystem helpers#
earthlens.base.safe_filename(value)
#
Sanitise an id into a filesystem-safe file stem.
Replaces every maximal run of characters outside the whitelist
(A-Z a-z 0-9 . _ -) with a single _, then strips any leading /
trailing _. Dots are kept, so a dataset id like
cmems_mod_glo_phy_my_0.083deg_P1D-m is returned unchanged while a
path-bearing key like planetary-computer/sentinel-2-l2a flattens to
planetary-computer_sentinel-2-l2a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The raw provider id / key. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A filesystem-safe stem: only |
str
|
trailing |
Examples:
- Path separators and Windows-illegal characters collapse to
_, while dots and hyphens survive: