Metadata-Version: 2.4
Name: snowflake-fxmacrodata
Version: 0.1.0
Summary: Load public FXMacroData responses into Snowflake
License-Expression: MIT
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=snowflake-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: snowflake-connector-python<5,>=4.8.1
Requires-Dist: filelock<5,>=4.2.9
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# FXMacroData for Snowflake

Load FXMacroData public responses through the official Snowflake Connector for
Python. Bounded batch inserts feed a temporary staging table, followed by a
transactional merge into your analytical table.

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

## Install and connect

Requires Python 3.10 or later and Snowflake Connector for Python 4.8.1 or later
within version 4. Install the supplied adapter wheel; its public client and
platform core dependencies resolve from PyPI:

```sh
python -m pip install /path/to/snowflake_fxmacrodata-0.1.0-py3-none-any.whl
```

Use a dedicated Snowflake connection with its current database and schema set.
This example uses interactive SSO; headless workloads should use your
organization's approved SDK authentication method and runtime secret store.
Expose the FXMacroData source key through the `FXMD_API_KEY` environment name.

```python
import os
import snowflake.connector
from fxmacrodata_platform_core import read
from fxmacrodata_snowflake import load

connection = snowflake.connector.connect(
    account=os.environ["SNOWFLAKE_ACCOUNT"],
    user=os.environ["SNOWFLAKE_USER"],
    authenticator="externalbrowser",
    warehouse=os.environ["SNOWFLAKE_WAREHOUSE"],
    database=os.environ["SNOWFLAKE_DATABASE"],
    schema=os.environ["SNOWFLAKE_SCHEMA"],
    paramstyle="qmark",
)
try:
    batch = read("release_calendar", {"currency": "usd"}, api_key_env="FXMD_API_KEY")
    result = load(batch, connection, "FXMACRODATA", paramstyle="qmark")
finally:
    connection.close()
```

One-, two- and three-part simple SQL names are accepted and normalized to
uppercase, matching Snowflake's unquoted identifier convention. Quoted,
case-sensitive names and SQL fragments are rejected. The database and schema
must exist. The caller needs table/stage creation and DML privileges. Use
`create_table=False` if an administrator has provisioned the envelope table with
`create_table_sql(table)`.

The loader must own the connection's transaction. Snowflake DDL can commit
an active transaction, so do not pass a connection with unrelated pending work.
`paramstyle` must match the connection (`qmark`, `numeric`, `format`, or
`pyformat`, the connector default). No global connector settings are changed.

Every operation exposed by `fxmacrodata_platform_core.operations()` is available,
including REST and MCP operations. The loader adds a tabular envelope without
changing the original public response. `record_json` retains the original record;
`response_json` retains the complete response, including pagination and metadata.
An empty response produces one envelope with `record_json = 'null'`, so absence of
data and the server's metadata remain inspectable. It is not an observation.

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.
Dates and announcement times remain source strings. No publication time is
inferred, and no missing value is filled. `value_text` and JSON preserve source
numbers supplied as strings. JSON numeric tokens follow the public Python client
parser, so original lexical precision is not guaranteed.

Select operations with the shared catalogue rather than constructing URLs:

```python
from fxmacrodata_platform_core import operations, schemas

available = operations()
input_schemas = schemas()
```

`load_operation` accepts `api_key_env`, `complete_history`, `max_pages`, and
`client_factory` for the public source reader. `max_pages` bounds history
pagination; an incomplete read raises an error before a destination load starts.
`batch_size` bounds destination blocks to 1–10,000 rows. `max_batch_bytes` also
bounds each block using a conservative JSON byte estimate (16 MiB by default,
128 MiB maximum). An oversized individual envelope is rejected before destination
changes; narrow the source date range to reduce the response size. The source response is
materialized before loading; choose a source date range suitable for memory.
Read the installed operation's schema for required arguments and date filters.

Supply source credentials through your runtime secret store, exposing only the
environment variable name to the adapter. Destination authentication belongs to
the official SDK connection you pass to the loader. The adapter neither saves nor
prints credentials and never constructs destination credentials for you.

The package licence covers this adapter code. FXMacroData data access and onward
redistribution remain subject to your subscription and applicable licence. Loading
data into a warehouse does not grant permission to publish or resell it.

## Retries and querying

The loader creates the destination and temporary table, then fills every bounded
block before beginning the destination DML transaction. This also keeps any
temporary binding-stage DDL issued by the connector outside the transaction.
It then begins, merges on operation, record ID and content hash, and commits.
A staging failure leaves destination rows untouched. A merge or commit failure
triggers rollback. If rollback itself fails, the loader avoids cleanup DDL that
could commit unresolved work.

Repeated exact envelopes are skipped; changed source records or metadata remain
distinct. Use one writer per destination table. Concurrent merges into standard
Snowflake tables are not an exactly-once guarantee. The loader never retries a
write automatically. After connection loss, inspect the transaction outcome
before retrying. `LoadResult.rows_submitted` counts unique envelopes offered to
the merge, rather than rows newly inserted.

```sql
SELECT CURRENCY, INDICATOR, DATE, VALUE,
       PARSE_JSON(RECORD_JSON):publication_time_status::STRING AS PUBLICATION_STATUS
FROM FXMACRODATA
WHERE RECORD_JSON != 'null';
```

[event_study.sql](examples/event_study.sql) joins source announcement times to
your licensed market-price table. Inspect source publication metadata separately
for point-in-time backtesting. [sharing.sql](examples/sharing.sql) shows a
customer-controlled secure share; sharing data requires the applicable rights
and recipient approval. This package does not create a Marketplace listing.

## Test

```sh
python -m pytest tests -q
```

Official SDK references:
[batch binding and transactions](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-example),
[connector API](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api).
