Source code for lcmd_db._schema
"""Runtime property schema introspection via the API."""
from __future__ import annotations
from ._http import fetch_json
from .exceptions import SchemaError
from .settings import settings
from .types import EntityType, PropertyInfo
[docs]
def schema(
subset: str,
entity_type: EntityType = EntityType.MOLECULES,
) -> list[PropertyInfo]:
"""Fetch property definitions for a subset from the API.
Raises:
DatasetNotFoundError: If the subset does not exist.
DownloadError: On network / HTTP errors.
SchemaError: If the response cannot be parsed.
"""
url = (
f"{settings.base_url}/api/v1/subsets/{subset}"
f"/properties?type={entity_type.value}"
)
data = fetch_json(url)
columns = data.get("columns")
if not isinstance(columns, list):
raise SchemaError(f"Unexpected response shape from {url}")
return [PropertyInfo.model_validate(col) for col in columns]