Utils — geocatalog.utils¶
Path and URI parsing, the shared retry policy and the UTC time helpers the catalog uses internally, at a public path.
Paths and URIs¶
geocatalog.utils.parse_uri(uri)
¶
Split a path or URI into a ParsedURI (see the module rules).
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/uri.py
geocatalog.utils.ParsedURI
dataclass
¶
A location split into the parts the catalog cares about.
Attributes:
| Name | Type | Description |
|---|---|---|
raw |
str
|
The input as a string. |
scheme |
str
|
Lower-case scheme; |
netloc |
str
|
Authority of a URI (bucket, host, container); |
path |
str
|
The path component — the URL path of a URI, the input itself for a plain local path. |
query |
str
|
The raw query string of a URI ( |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/uri.py
is_local
property
¶
True for plain paths and file:// URIs.
is_remote
property
¶
True for every <scheme>:// URI except file://.
is_zarr
property
¶
True when the location is a .zarr store (trailing slash allowed).
name
property
¶
Final path component ("" for a bare bucket or host).
suffix
property
¶
Extension of name, with the dot ("" if none).
gdal_path()
¶
GDAL /vsi*/ path for a remote URI GDAL can read, else None.
s3://bucket/key → /vsis3/bucket/key; http(s)://… →
/vsicurl/http(s)://…; abfs[s]://container@account…/key →
/vsiaz/container/key. Credentials come from GDAL's usual
configuration (AWS_*, GOOGLE_APPLICATION_CREDENTIALS,
AZURE_STORAGE_*, …).
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/uri.py
local_path()
¶
The filesystem path of a local location; None for remote URIs.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/uri.py
Retries¶
geocatalog.utils.retry_transient_io(fn, *args, retries, **kwargs)
¶
Call fn with retries for transient remote I/O exceptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., T]
|
Callable to invoke. |
required |
*args
|
Any
|
Positional args forwarded to |
()
|
retries
|
int
|
Number of retries after the initial attempt. |
required |
**kwargs
|
Any
|
Keyword args forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Whatever |
Notes
Only RasterioIOError, urllib3.exceptions.ReadTimeoutError, and
non-fatal OSError instances are retried; an HTTP error (urllib's
HTTPError or one carrying a response.status_code) only for
408 / 425 / 429 and any 5xx. Fatal OSError subclasses
(FileNotFoundError, PermissionError, IsADirectoryError,
NotADirectoryError, InterruptedError) are re-raised on the first
attempt — there is no benefit to waiting on them.
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/retry.py
Time¶
geocatalog.utils.to_utc_ts(value)
¶
Coerce any datetime-like to a UTC-aware pd.Timestamp.
Naive inputs are assumed UTC (the catalog's stored time-axis contract) and localised; tz-aware inputs in other zones are converted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Anything |
required |
Returns:
| Type | Description |
|---|---|
Timestamp
|
A tz-aware |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/timeutil.py
geocatalog.utils.to_naive_utc(value)
¶
Coerce a datetime-like to the catalog's stored form: naive, in UTC.
Naive inputs are returned unchanged (they are UTC by contract);
tz-aware inputs are converted to UTC and the zone dropped. NaT
passes through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Anything |
required |
Returns:
| Type | Description |
|---|---|
Timestamp
|
A tz-naive |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/timeutil.py
geocatalog.utils.to_rfc3339(value)
¶
Serialize a datetime-like as RFC 3339 in UTC with a Z suffix.
.isoformat() on a UTC-aware Timestamp yields ...+00:00; the
STAC-canonical form uses Z, so the offset is normalised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Anything |
required |
Returns:
| Type | Description |
|---|---|
An RFC 3339 string, e.g. ``"2024-06-15T10
|
00:00Z"``. |
Source code in packages/geotoolz-catalog/src/geocatalog/_src/utils/timeutil.py
geocatalog.utils.is_time_invariant(interval)
¶
True for the sentinel interval of a time-invariant row.