Skip to main content
Version: Next

ts_shape.loader.metadata.metadata_db_loader

Classes
NameDescription
DatapointDBLoad datapoint metadata per device from the PostgreSQL config repository.

DatapointDB​

classsource
DatapointDB(
device_names: list[str],
db_user: str,
db_pass: str,
db_host: str,
output_path: str = "data",
required_uuid_list: list[str] | None = None,
filter_enabled: bool = True,
*,
db_port: int = 5432,
db_name: str = "config_repository",
db_driver: str = POSTGRES_DRIVER
)

Load datapoint metadata per device from the PostgreSQL config repository.

Needs the postgres extra (pip install ts-shape[postgres]). repr(db) masks the password.

Functions
NameDescription
get_all_uuidsReturn a dictionary of UUIDs for each device.
get_all_metadataReturn a dictionary of metadata for each device.
display_dataframeDisplay metadata as a DataFrame for a specific device or all devices.
Parameters
NameTypeDescriptionDefault
device_nameslist[str]List of device names to retrieve metadata for.required
db_userstrDatabase user.required
db_passstrDatabase password.required
db_hoststrDatabase host.required
output_pathstrDirectory to save JSON files.'data'
required_uuid_listlist[str] | NoneList of UUIDs to filter the metadata (optional).None
filter_enabledboolWhether to filter metadata by "enabled == True" and "archived == False" (default is True).True
db_portintDatabase port. Default 5432.5432
db_namestrDatabase name. Default "config_repository".'config_repository'
db_driverstrDB-API driver. Default "psycopg2" (the postgres extra).POSTGRES_DRIVER
Raises
TypeDescription
ImportErrorSQLAlchemy or the database driver is not installed.

url​

propertysource
url: URL

The connection URL; str(url) masks the password.

get_all_uuids​

methodsource
get_all_uuids() -> dict[str, list[str]]

Return a dictionary of UUIDs for each device.

get_all_metadata​

methodsource
get_all_metadata() -> dict[str, list[dict[str, str]]]

Return a dictionary of metadata for each device.

display_dataframe​

methodsource
display_dataframe(
device_name: str | None = None, aggregate: bool = False
) -> None

Display metadata as a DataFrame for a specific device or all devices.

Parameters
NameTypeDescriptionDefault
device_namestr | NoneName of the device to display metadata for (optional).None
aggregateboolIf True, combine metadata from all devices into a single DataFrame.False