currency_api.parquet

Documentation for eth_defi.currency_api.parquet Python module.

Cleaned Parquet materialisation for currency API exchange rates.

The raw DuckDB database remains the auditable source of currency API records. This module creates a deterministic, sanitised Parquet snapshot for consumers that must not apply rate-cleaning policy themselves.

Module Attributes

EXCHANGE_RATE_PARQUET_SCHEMA

Stable schema for the cleaned exchange-rate consumer export.

Functions

load_cleaned_exchange_rates(source_path)

Read and clean all exchange-rate rows from an existing DuckDB database.

materialise_exchange_rate_parquet(...)

Atomically materialise one cleaned Parquet snapshot from DuckDB.

Classes

ExchangeRateParquetSnapshot

Verified cleaned exchange-rate Parquet snapshot.

EXCHANGE_RATE_PARQUET_SCHEMA = date: date32[day] not null base_currency: string not null quote_currency: string not null rate: double not null source: string not null written_at: timestamp[us]

Stable schema for the cleaned exchange-rate consumer export.

class ExchangeRateParquetSnapshot

Bases: object

Verified cleaned exchange-rate Parquet snapshot.

path: pathlib.Path

Local destination path of the materialised Parquet file.

row_count: int

Number of cleaned exchange-rate rows in the snapshot.

sha256: str

SHA-256 digest of the byte-identical local Parquet file.

__init__(path, row_count, sha256)
Parameters
Return type

None

load_cleaned_exchange_rates(source_path)

Read and clean all exchange-rate rows from an existing DuckDB database.

Uses DuckDB read-only mode and intentionally bypasses CurrencyRateDatabase: that mutable storage class creates directories and may initialise schema. The returned frame is sorted by its logical key and has stable column order.

Parameters

source_path (pathlib.Path) – Existing raw currency API DuckDB database.

Returns

Sanitised DataFrame with date, currency, rate, source and naive-UTC written_at columns.

Raises
Return type

pandas.DataFrame

materialise_exchange_rate_parquet(source_path, destination_path)

Atomically materialise one cleaned Parquet snapshot from DuckDB.

The write is deterministic for unchanged source rows: row order, column order and row values are all fixed, and no materialisation timestamp is inserted. A failed conversion leaves the prior destination untouched.

Parameters
  • source_path (pathlib.Path) – Existing raw currency API DuckDB database opened read-only.

  • destination_path (pathlib.Path) – Cleaned Parquet destination, normally below the pipeline data directory.

Returns

Verified Parquet snapshot metadata.

Return type

eth_defi.currency_api.parquet.ExchangeRateParquetSnapshot