kde_cpi.data.loader module

Async PostgreSQL integration for CPI datasets.

class kde_cpi.data.loader.CpiDatabaseLoader(dsn=None, schema='public', connection_kwargs=NOTHING)[source]

Bases: object

Persist CPI datasets into PostgreSQL using asyncpg primitives.

Parameters:
async bulk_load(dataset, *, truncate=True)[source]

Copy the full dataset into PostgreSQL, optionally truncating first.

Return type:

None

Parameters:
async close()[source]

Close the open connection, if any.

Return type:

None

async connect(**overrides)[source]

Establish (or reuse) the async connection.

Return type:

Connection

Parameters:

overrides (Any)

connection_kwargs: dict[str, Any]
dsn: str | None
async ensure_schema()[source]

Create the CPI tables if they do not already exist.

Return type:

None

async fetch_dataset()[source]

Reconstruct a Dataset from the current database contents.

Return type:

Dataset

async merge_dataset(dataset)[source]

Synchronize metadata and upsert observations in place.

Return type:

None

Parameters:

dataset (Dataset)

schema: str
async sync_metadata(dataset)[source]

Upsert mapping tables and series definitions without touching observations.

Return type:

None

Parameters:

dataset (Dataset)

async upsert_observations(observations)[source]

Upsert one or more observation rows.

Return type:

None

Parameters:

observations (Iterable[Observation])