Metadata-Version: 2.4
Name: arrow-flight-fxmacrodata
Version: 0.1.0
Summary: Serve public FXMacroData responses over Apache Arrow Flight
License-Expression: MIT
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=arrow-flight-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: pyarrow<27,>=25
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# FXMacroData for Apache Arrow Flight

Serve FXMacroData public responses to any Arrow Flight client from a server
you run. Flight clients in Python, Java, C++, Go, Rust and R, plus engines
such as DuckDB and Dremio, can then pull macro announcements, calendars, FX
and positioning data as Arrow record batches without an HTTP client or JSON
parsing of their own.

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

## Install

Requires Python 3.10 or later and `pyarrow` 25 or later (Flight is bundled
in the standard wheels). 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/arrow-flight-fxmacrodata
```

## Example

Start a server on your own network. USD data is served without a key:

```python
from fxmacrodata_flight import FXMacroDataFlightServer

server = FXMacroDataFlightServer("grpc://127.0.0.1:8815")
print("listening on", server.port)
server.serve()
```

Then from any Flight client:

```python
import json
import pyarrow.flight as flight

client = flight.connect("grpc://127.0.0.1:8815")
request = {"operation": "indicator_history",
           "arguments": {"currency": "usd", "indicator": "policy_rate"}}
info = client.get_flight_info(flight.FlightDescriptor.for_command(json.dumps(request).encode()))
table = client.do_get(info.endpoints[0].ticket).read_all()
print(table.filter(table["value"].is_valid()).select(["date", "value"]))
```

`list_flights` returns one flight per served operation with the fixed
schema, so clients can discover the catalogue. A command descriptor is JSON
with `operation`, optional `arguments` (an object matching the operation's
input schema) and optional `complete_history` (default `true`). Pass
`allowed_operations=[...]` to serve a subset of the catalogue and
`max_pages` to bound history pagination for every read.

The server binds to the location you give it. Flight itself is unencrypted
and unauthenticated unless you configure TLS and authentication through the
`FlightServerBase` options (`tls_certificates`, `auth_handler`,
`middleware`), which are passed through unchanged. Bind to a loopback or
private address unless you have done so.

## Credentials

Set `FXMD_API_KEY` in the server's environment or secret manager and pass its
name: `FXMacroDataFlightServer(location, api_key_env="FXMD_API_KEY")`. The
server resolves the value for every upstream read; clients never send a key.
Requests whose arguments carry `api_key`, tokens, URLs or endpoint overrides
are rejected with a generic message before any read occurs. Omit
`api_key_env` for anonymous access.

## Data semantics

Every flight has the same schema: `operation`, `source_url`, `record_id`,
`currency`, `indicator`, `date`, `announcement_datetime`, `value`,
`value_text`, `record_json`, `response_json` and `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 streams one envelope row with `record_json = "null"`; it is not an
observation. Dates and announcement times remain source strings. No
publication time is inferred and no missing value is filled. `record_id` is
a stable hash of the operation and record; `content_hash` is the SHA-256 of
the canonical JSON of the ten source columns.

## Delivery guarantee

Each `do_get` performs one fresh read and streams the complete response. The
server holds no cache and no state between calls; two identical requests
produce two upstream reads. An upstream failure ends the stream with a
`FlightUnavailableError` whose message carries no upstream detail.

## Development

Run the offline tests with `python -m pytest tests -q`. They start the server
on an ephemeral loopback port inside the test process with the public reader
monkeypatched and never call the live service.
