Metadata-Version: 2.4
Name: deltalake-fxmacrodata
Version: 0.1.0
Summary: Load public FXMacroData responses into Delta Lake tables
License-Expression: MIT
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=deltalake-fxmacrodata&utm_content=package
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fxmacrodata-platform-core==0.1.0
Requires-Dist: deltalake<2,>=1.6.6
Requires-Dist: pyarrow<27,>=25
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# FXMacroData for Delta Lake

Load FXMacroData public responses into Delta Lake tables with the official
`deltalake` Python package (delta-rs). Store macro announcements, calendars,
FX and positioning data next to your own lakehouse tables while retaining the
source payload and revision metadata.

[FXMacroData documentation](https://fxmacrodata.com/documentation/reference?utm_source=github&utm_medium=referral&utm_campaign=deltalake-fxmacrodata&utm_content=readme)

## Install

Requires Python 3.10 or later and `deltalake` 1.6.6 or later. Install this
package and its adjacent public client dependencies from the distribution
supplied to you:

```sh
python -m pip install /path/to/fxmacrodata-public-client /path/to/fxmacrodata-platform-core /path/to/deltalake-fxmacrodata
```

## Example

USD data is available without a key:

```python
from fxmacrodata_platform_core import read
from fxmacrodata_deltalake import merge_load

batch = read("indicator_history", {"currency": "usd", "indicator": "policy_rate"})
result = merge_load(batch, "./lake/fxmacrodata")
print(result.rows, "envelopes submitted in", result.batches, "blocks")
```

Any object-store location accepted by `deltalake` works, for example
`s3://bucket/fxmacrodata` or `abfss://container@account.dfs.core.windows.net/fxmacrodata`.
Pass the store's own settings through `storage_options`; they are handed to
`deltalake` untouched and are never logged.

## Credentials

Set `FXMD_API_KEY` in your environment or secret manager and pass its name
to `read` (or to `load_operation`) through `api_key_env`. Omit it for
anonymous access. Destination credentials belong to your object store
configuration, never to this package.

## Data semantics

Columns are `operation`, `source_url`, `record_id`, `currency`, `indicator`,
`date`, `announcement_datetime`, `value`, `value_text`, `record_json`,
`response_json` and the loader's `content_hash`. Only `value` is numeric
(nullable float64); every other column is a nullable string. `record_json`
retains the original record and `response_json` retains the complete
response, including pagination and metadata. An empty response produces one
envelope row with `record_json = 'null'`, so absence of data and the server's
metadata remain inspectable; it is not an observation. Dates and announcement
times remain source strings. No publication time is inferred and no missing
value is filled. `content_hash` is the SHA-256 of the canonical JSON of the
ten source columns. Writes use `schema_mode="merge"`, so additive columns in
future versions never break an existing table.

## Delivery guarantee

`load` appends bounded blocks of `batch_size` rows (1 to 10,000). It is
at-least-once: a repeated load produces duplicate rows, and a failed block
is never retried automatically; earlier blocks may already be committed.

`merge_load` is idempotent. It runs a Delta `MERGE` keyed on
`operation`, `record_id` and `content_hash` with `WHEN NOT MATCHED THEN INSERT`,
so retrying the same source batch adds nothing. Changed record data or
response metadata yields a new `content_hash` and is retained as a new row
with the same `record_id`; query the latest hash per record for a
current view.

`load_operation` reads one operation and loads it in one call. It accepts
`api_key_env`, `complete_history`, `max_pages` and `client_factory` for the
public reader; `max_pages` bounds history pagination, and an incomplete read
raises before the destination is touched.

## Development

Run the offline tests with `python -m pytest tests -q`. They write to a local
temporary Delta table and never call the live service or a remote store.
