Skip to content

timescale_loader

timescale_loader ¤

TimescaleDBDataAccess ¤

TimescaleDBDataAccess(
    start: str,
    end: str,
    uuids: list[str],
    db_config: dict[str, Any],
)

Load timeseries data for given UUIDs and a time range from TimescaleDB.

Needs the postgres extra (pip install ts-shape[postgres]: SQLAlchemy and the psycopg2 driver). Creating the loader does not connect; the first fetch does. repr(loader) masks the password.

Initialize the TimescaleDB loader and create the database engine.

Parameters:

Name Type Description Default
start str

Start of the time range (inclusive) to query.

required
end str

End of the time range (inclusive) to query.

required
uuids list[str]

List of UUIDs to retrieve data for.

required
db_config dict[str, Any]

Connection settings with the keys db_user, db_pass, db_host and db_name, and optionally db_port (default 5432) and db_driver (the DB-API driver, default "psycopg2"). The password is used as is; it needs no URL escaping.

required

Raises:

Type Description
ImportError

SQLAlchemy or the database driver is not installed.

fetch_data_as_parquet ¤

fetch_data_as_parquet(output_dir: str) -> None

Retrieve timeseries data from TimescaleDB and save it as Parquet files.

Rows are grouped by the hour of systime and written to one file per UUID and hour at <output_dir>/year/month/day/hour/<uuid>.parquet.

Parameters:

Name Type Description Default
output_dir str

Base directory to save the Parquet files.

required

fetch_data_as_dataframe ¤

fetch_data_as_dataframe() -> pd.DataFrame

Retrieve timeseries data from TimescaleDB as a single DataFrame.

Returns:

Type Description
DataFrame

A combined DataFrame with data for all specified UUIDs within the time

DataFrame

range.