Skip to content

radiens_data_catalog.config

Configuration loading for radiens-data-catalog.

Config.from_file lists where it looks for the config file.

Relative paths in the config file (credentials_path, local_data_dir, catalog_path) are resolved against the config file's own directory, not the process's current working directory, so a config works the same from a repo-root script or a notebook in a subdirectory.

Classes

Config dataclass

Configuration for radiens-data-catalog.

All path fields (credentials_path, local_data_dir, catalog_path) support ~ and $ENV_VAR expansion and are resolved to absolute paths on construction. Typically created via Config.from_file() rather than directly.

When loaded via Config.from_file(), relative paths resolve against the config file's own directory. When constructed directly (Config(...)), relative paths resolve against the current working directory.

ATTRIBUTE DESCRIPTION
credentials_path

Path to the Google service account credentials JSON file.

TYPE: str

root_folder_id

Google Drive folder ID of the data root folder.

TYPE: str

local_data_dir

Local directory where datasets will be downloaded.

TYPE: str

catalog_path

Path to the catalog JSON file (created by Catalog.scan()). Defaults to catalog.json in local_data_dir.

TYPE: str

METHOD DESCRIPTION
__post_init__

Expand ~ and $ENV_VARS in all path fields and resolve to absolute paths.

from_file

Load config from a JSON file.

Functions

__post_init__
__post_init__() -> None

Expand ~ and $ENV_VARS in all path fields and resolve to absolute paths.

from_file classmethod
from_file(path: str | None = None) -> Config

Load config from a JSON file.

Resolution order when path is None:

  1. RADIENS_DATA_CATALOG_CONFIG environment variable.
  2. .secrets/config.json, then config.json, searched starting in the current working directory and then each parent directory up to the filesystem root (closest directory wins).
  3. ~/.config/radiens-data-catalog/config.json in the user's home directory.
  4. /etc/radiens-data-catalog/config.json.
PARAMETER DESCRIPTION
path

Path to the config JSON file. When None, the resolution order above is used.

TYPE: str | None DEFAULT: None

Relative paths in the config file are resolved against the config file's own directory, not the current working directory.

RETURNS DESCRIPTION
Config

A Config instance with all paths expanded and resolved.

RAISES DESCRIPTION
FileNotFoundError

If no config file can be located.

JSONDecodeError

If the config file is not valid JSON.

TypeError

If the JSON fields do not match the Config field names.