Skip to content

metadata_db_loader

metadata_db_loader ¤

DatapointDB ¤

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.

Initialize the DatapointDB class and load metadata for each device.

Parameters:

Name Type Description Default
device_names list[str]

List of device names to retrieve metadata for.

required
db_user str

Database user.

required
db_pass str

Database password.

required
db_host str

Database host.

required
output_path str

Directory to save JSON files.

'data'
required_uuid_list list[str] | None

List of UUIDs to filter the metadata (optional).

None
filter_enabled bool

Whether to filter metadata by "enabled == True" and "archived == False" (default is True).

True
db_port int

Database port. Default 5432.

5432
db_name str

Database name. Default "config_repository".

'config_repository'
db_driver str

DB-API driver. Default "psycopg2" (the postgres extra).

POSTGRES_DRIVER

Raises:

Type Description
ImportError

SQLAlchemy or the database driver is not installed.

url property ¤

url: URL

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

get_all_uuids ¤

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

Return a dictionary of UUIDs for each device.

get_all_metadata ¤

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

Return a dictionary of metadata for each device.

display_dataframe ¤

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

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

Parameters:

Name Type Description Default
device_name str | None

Name of the device to display metadata for (optional).

None
aggregate bool

If True, combine metadata from all devices into a single DataFrame.

False