Metadata-Version: 2.4
Name: polars-fxmacrodata
Version: 0.1.0
Summary: Lazy Polars IO source for FXMacroData macroeconomic and market data
Author-email: FXMacroData <info@fxmacrodata.com>
License: MIT License
        
        Copyright (c) 2026 FXMacroData
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://fxmacrodata.com/?utm_source=pypi&utm_medium=referral&utm_campaign=polars-fxmacrodata&utm_content=package
Project-URL: Documentation, https://fxmacrodata.com/documentation/reference?utm_source=pypi&utm_medium=referral&utm_campaign=polars-fxmacrodata&utm_content=docs
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: polars==1.38.1
Requires-Dist: fxmacrodata-platform-core==0.1.0
Dynamic: license-file

# FXMacroData for Polars

Query FXMacroData as a native Polars lazy IO source. Combine macroeconomic releases,
FX, commodities, positioning and research data with your own datasets using the
same expressions, joins and sinks as other Polars scans.

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

## Install

Install the `polars-fxmacrodata` wheel together with its
`fxmacrodata-platform-core` and `fxmacrodata-public-client` dependencies. The Polars IO
plugin API is unstable, so this package pins the supported Polars release.

From the supplied packages directory:

```sh
python -m pip install ./fxmacrodata-public-client ./fxmacrodata-platform-core ./polars-fxmacrodata
```

```python
import polars as pl
from polars_fxmacrodata import operation_catalog, scan_fxmacrodata

# Local discovery includes operation arguments and requires no remote request.
print(operation_catalog().select("name", "description"))
print(operation_catalog().filter(pl.col("name") == "indicator_history"))

history = scan_fxmacrodata(
    "indicator_history",
    {"currency": "USD", "indicator": "policy_rate"},
    api_key_env="FXMD_API_KEY",
)
result = (
    history.filter(pl.col("value").is_not_null())
    .select("date", "value", "record_json")
    .collect()
)
```

Set `FXMD_API_KEY` using your environment or secret manager. Pass its name through
`api_key_env`; the source resolves its value when executing the query. Omitting
`api_key_env` explicitly selects anonymous access. Credentials do not belong in
arguments, notebooks, saved query plans or source control.

`scan_fxmacrodata` builds a plan without making a request. `collect`, a sink, or
another executing operation performs the read. Historical operations follow all
pages by default; `complete_history=False` requests the supplied page only.
`max_pages` defaults to 10,000 and raises on an incomplete history instead of
silently truncating it. Normal API access and licence terms apply.

## Add release context to portfolio positions

Suppose `positions.parquet` contains `currency` and `position_usd` columns:

```python
calendar = scan_fxmacrodata(
    "release_calendar", {"currency": "USD"}, api_key_env="FXMD_API_KEY"
)
positions = pl.scan_parquet("positions.parquet")
exposure_by_event = (
    calendar.filter(pl.col("announcement_datetime").is_not_null())
    .select("currency", "indicator", "announcement_datetime", "record_json")
    .join(positions, on="currency", how="inner")
    .collect()
)
```

Calendar times retain the API's original strings. Unknown publication times stay
null. An observation's period date is not substituted for its release time.

## Data and query semantics

The fixed schema contains `operation`, `source_url`, `record_id`, `currency`,
`indicator`, `date`, `announcement_datetime`, `value`, `value_text`, `record_json`
and `response_json`. `value` is nullable Float64; other columns are nullable
String. `record_json` preserves the original record and `response_json` preserves
the complete response envelope, including metadata and revision information.
Empty results retain an envelope row with a null record. Inspect `source_schema()`
without fetching data.

The scanner applies pushed predicates before column projection and honours the
engine's row limit and batch-size hint. Predicates run in Polars and are not
translated into different API filters. Supply documented operation arguments to
reduce the remote dataset. The complete response is fetched before it is emitted
in dataframe batches; a final `head()` limits the result, not the remote history
request. Collecting the same plan again performs a fresh read.

All public REST operations and packaged MCP tools are exposed through the
operation catalog. MCP tool names have an `mcp_` prefix. Authentication and
endpoint-specific access requirements remain those of the selected operation.

## Development

Run the offline source tests with `python -m pytest tests`. They exercise native
Polars collection with fixture responses and never call the live service.
