Metadata-Version: 2.4
Name: rabbitmq-fxmacrodata
Version: 0.1.0
Summary: Publish public FXMacroData responses to RabbitMQ
License-Expression: MIT
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=rabbitmq-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: pika<2,>=1.4.4
Provides-Extra: test
Requires-Dist: pytest<9,>=8; extra == "test"
Dynamic: license-file

# FXMacroData for RabbitMQ

Publish FXMacroData public responses to a RabbitMQ exchange with the official
`pika` Python client. Route macro announcements to your own queues while
retaining the source payload and revision metadata.

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

## Install and connect

Requires Python 3.10 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/rabbitmq-fxmacrodata
```

Configure `RABBITMQ_URL` (an `amqps://` URL with the credentials your
administrator provides) in your runtime secret store. Then publish to a
customer-owned exchange:

```python
import os
import pika
from fxmacrodata_platform_core import read
from fxmacrodata_rabbitmq import publish

connection = pika.BlockingConnection(pika.URLParameters(os.environ["RABBITMQ_URL"]))
try:
    channel = connection.channel()
    batch = read("indicator_history", {"currency": "usd", "indicator": "policy_rate"})
    result = publish(batch, channel, ("fxmacrodata", "usd.policy_rate"), confirm=True)
    print(result.messages, "messages in", result.batches, "blocks")
finally:
    connection.close()
```

The exchange and any bound queues must already exist. The destination is an
`(exchange, routing_key)` tuple; names accept letters, digits, `_`, `.`, `:`
and `-` up to 255 characters. Use `("", "queue-name")` for the default
exchange and `("exchange-name", "")` for a fanout exchange. Wildcards, URLs
and other values are rejected before any publish.

Every operation exposed by `fxmacrodata_platform_core.operations()` is
available, including REST and MCP operations. `publish_operation` reads one
operation and publishes it in a single call:

```python
from fxmacrodata_rabbitmq import publish_operation

publish_operation("release_calendar", {"currency": "usd"}, channel, ("fxmacrodata", "usd.calendar"),
                  api_key_env="FXMD_API_KEY")
```

## Message format

Each envelope row becomes one persistent message (`delivery_mode=2`). The
body is canonical UTF-8 JSON with the keys `operation`, `source_url`,
`record_id`, `currency`, `indicator`, `date`, `announcement_datetime`,
`value`, `value_text`, `record_json`, `response_json` and the publisher's
`content_hash` (SHA-256 of the ten source columns). Only `value` is numeric.
Dates and announcement times remain source strings. No publication time is
inferred, and no missing value is filled. `record_json` retains the original
record; `response_json` retains the complete response, including pagination
and metadata. An empty response produces one message with `record_json`
equal to `"null"`, so absence of data and the server's metadata remain
inspectable. It is not an observation.

`message_id` is `operation:record_id:content_hash`; the same source record
with the same content always produces the same id, and changed data or
metadata produces a different one. `content_type` is `application/json` and
the headers `operation`, `record_id`, `content_hash` and `source_url` are set
on every message. No timestamp property is derived from the data.

## Delivery guarantee

Delivery is at-least-once. Messages are published in blocks of `batch_size`
rows (1 to 10,000, 1,000 by default). With `confirm=True` the channel enters
publisher-confirm mode before the first publish, so a message the broker
rejects or cannot route fails its block; without confirms, a broker-side
failure surfaces only when the channel closes. A failed block raises
`PublishError` without the broker's own diagnostic text and is not retried;
earlier blocks may already be delivered. Consumers should deduplicate on
`message_id`, or on the `operation`, `record_id` and `content_hash` headers.

`max_message_bytes` (16 MiB by default) rejects an individual envelope larger
than the budget before anything is published; keep it within the broker's
`max_message_size`, and narrow the source date range to reduce the response
size. The source response is materialized before publishing; choose a source
date range suitable for memory.

`publish_operation` accepts `api_key_env`, `complete_history`, `max_pages`
and `client_factory` for the public source reader. Supply source credentials
through your runtime secret store, exposing only the environment variable
name; omit `api_key_env` for anonymous USD access. Destination authentication
belongs to the connection you open with the official client. The adapter
neither saves nor prints credentials and never places one in a message or
header.

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

## Development

Tests run offline against an in-memory fake channel:

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

Official SDK reference:
[pika BlockingChannel.basic_publish](https://pika.readthedocs.io/en/stable/modules/adapters/blocking.html?utm_source=pypi&utm_medium=referral&utm_campaign=rabbitmq-fxmacrodata&utm_content=upstream-reference#pika.adapters.blocking_connection.BlockingChannel.basic_publish).
