Metadata-Version: 2.4
Name: pyiceberg-fxmacrodata
Version: 0.1.0
Summary: Load public FXMacroData responses into Apache Iceberg tables with PyIceberg
License-Expression: MIT
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=pyiceberg-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: pyiceberg<1,>=0.12.0
Requires-Dist: pyarrow<27,>=25
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# FXMacroData for Apache Iceberg

Load FXMacroData public responses into Apache Iceberg tables with PyIceberg.
Keep macro announcements, calendars, FX and positioning data in the same
catalog as your own tables while retaining the source payload and revision
metadata.

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

## Install

Requires Python 3.10 or later and PyIceberg 0.12 or later. Install this
package and its adjacent public client dependencies from the distribution
supplied to you, together with the PyIceberg extras for your catalog and
object store (for example `pyiceberg[sql-sqlite]`, `pyiceberg[glue]` or
`pyiceberg[s3fs]`):

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

## Example

USD data is available without a key:

```python
from pyiceberg.catalog import load_catalog
from fxmacrodata_platform_core import read
from fxmacrodata_iceberg import load

catalog = load_catalog("default")  # configured in ~/.pyiceberg.yaml
batch = read("indicator_history", {"currency": "usd", "indicator": "policy_rate"})
result = load(batch, catalog, "analytics.fxmacrodata", batch_size=1000)
print(result.rows, "envelopes appended in", result.batches, "blocks")
```

The namespace (`analytics`) must already exist. By default the loader creates
the table if absent through `catalog.create_table_if_not_exists`; set
`create_table=False` to use a table provisioned by your administrator, and
`iceberg_schema()` returns the schema it expects. Identifiers are dotted
simple names with at least a namespace and a table (`analytics.fxmacrodata`),
or a tuple of parts. Quoted names, SQL fragments and URL-like names are
rejected before the catalog is contacted.

## 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. Catalog and object-store credentials belong to the
PyIceberg catalog object you construct and pass in; this package never builds
connection settings or reads destination secrets.

## 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
(optional `double`); every other column is an optional `string`. The schema
declares no identifier fields. `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.

## Delivery guarantee

`load` appends bounded blocks of `batch_size` rows (1 to 10,000) through
`Table.append`, each block as its own snapshot. Delivery is at-least-once:
repeating a load appends the same envelopes again, and a failed block is not
retried automatically; earlier blocks may already be committed. Deduplicate
downstream with a `MERGE INTO` keyed on `operation`, `record_id` and
`content_hash` in your query engine (Spark, Trino, Dremio, Flink) when you
need exactly-once storage semantics. Changed record data or response
metadata produces a distinct `content_hash` with the same `record_id`.

`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 use an in-test
fake catalog that records appended Arrow tables and never call the live
service or a real catalog.
