Source code for geestac.stac
"""STAC Base class."""
import requests
[docs]
class STAC:
"""Base STAC class."""
def __init__(self, href: str, name: str, parent=None):
"""Base STAC class.
Fetch the STAC data at init.
Args:
href: URL of the catalog / dataset.
name: name of the catalog / dataset.
parent: parent STAC class.
"""
[docs]
def is_lazy(self) -> bool:
"""Lazy means it has not fetched the real data yet."""
return self._lazy
[docs]
def __repr__(self):
"""Object representation."""
return f"{self.name}{' (lazy)' if self.is_lazy() else ''}"
@property
[docs]
def description(self):
"""Description of the Catalog."""
return self.data.get("description")
@property
[docs]
def version(self):
"""STAC Version."""
return self.data.get("stac_version")
[docs]
def __call__(self):
"""Fetch the data."""
if self.is_lazy():
self.data = requests.get(self.href).json()
self._lazy = False
return self
[docs]
def __eq__(self, other):
"""Compare with another object."""
if not isinstance(other, STAC):
return False
data = self.data == other.data
name = self.name == other.name
return data and name