Skip to content

feat: support listing known catalogs #2088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ def load_catalog(name: Optional[str] = None, **properties: Optional[str]) -> Cat
raise ValueError(f"Could not initialize catalog with the following properties: {properties}")


def list_catalogs() -> List[str]:
return _ENV_CONFIG.get_known_catalogs()


def delete_files(io: FileIO, files_to_delete: Set[str], file_type: str) -> None:
"""Delete files.

Expand Down
6 changes: 6 additions & 0 deletions pyiceberg/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def get_catalog_config(self, catalog_name: str) -> Optional[RecursiveDict]:
return catalog_conf
return None

def get_known_catalogs(self) -> List[str]:
catalogs = self.config.get(CATALOG, {})
if not isinstance(catalogs, dict):
raise ValueError("Catalog configurations needs to be an object")
return list(catalogs.keys())

def get_int(self, key: str) -> Optional[int]:
if (val := self.config.get(key)) is not None:
try:
Expand Down
9 changes: 9 additions & 0 deletions tests/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def test_fix_nested_objects_from_environment_variables() -> None:
}


@mock.patch.dict(os.environ, EXAMPLE_ENV)
@mock.patch.dict(os.environ, {"PYICEBERG_CATALOG__DEVELOPMENT__URI": "https://dev.service.io/api"})
def test_list_all_known_catalogs() -> None:
assert Config().get_known_catalogs() == [
"production",
"development",
]


def test_from_configuration_files(tmp_path_factory: pytest.TempPathFactory) -> None:
config_path = str(tmp_path_factory.mktemp("config"))
with open(f"{config_path}/.pyiceberg.yaml", "w", encoding=UTF8) as file:
Expand Down