Haystack integration for the UniRate currency-exchange API — components for FX rate lookups, conversion, and currency listings in Haystack pipelines.
Project description
haystack-unirate
Haystack integration for the UniRate API — drop-in currency-exchange components for Haystack 2.x pipelines.
UniRate provides 593+ fiat, crypto, and commodity exchange rates. Latest rates, conversions, and currency listings are available on the free tier; historical and time-series endpoints require a Pro plan.
Why this package
There's no first-class FX component in core Haystack. This package gives you
typed, tested @component-decorated blocks that slot straight into a
Pipeline — with Secret-based API-key handling and full to_dict /
from_dict serialization so pipelines round-trip to YAML/JSON cleanly.
Install
pip install haystack-unirate
Quick start
import os
os.environ["UNIRATE_API_KEY"] = "..." # https://unirateapi.com
from haystack.utils import Secret
from haystack_unirate import (
UniRateConverter,
UniRateCurrencies,
UniRateExchangeRate,
)
api_key = Secret.from_env_var("UNIRATE_API_KEY")
rate = UniRateExchangeRate(api_key=api_key)
print(rate.run(from_currency="USD", to_currency="GBP")["rate"]) # 0.79
converter = UniRateConverter(api_key=api_key)
print(converter.run(from_currency="USD", to_currency="EUR", amount=100)["result"]) # 92.5
currencies = UniRateCurrencies(api_key=api_key)
print(currencies.run()["currencies"][:5])
In a pipeline
from haystack import Pipeline
from haystack.utils import Secret
from haystack_unirate import UniRateConverter
pipeline = Pipeline()
pipeline.add_component(
"convert", UniRateConverter(api_key=Secret.from_env_var("UNIRATE_API_KEY"))
)
result = pipeline.run(
{"convert": {"from_currency": "USD", "to_currency": "JPY", "amount": 250}}
)
print(result["convert"]["result"])
Components
| Component | Output sockets | Description |
|---|---|---|
UniRateExchangeRate |
rate: float, rates: dict |
Latest rate for a pair; if to_currency is omitted, rates holds every supported target and rate is None. |
UniRateConverter |
result: float |
Convert amount from one currency to another at the latest rate. |
UniRateCurrencies |
currencies: list[str] |
All currency codes UniRate can convert between. |
Each component takes:
| Constructor arg | Env var | Default |
|---|---|---|
api_key (Secret) |
UNIRATE_API_KEY |
— (required) |
base_url |
— | https://api.unirateapi.com |
timeout |
— | 30.0 (seconds) |
Error handling
Non-2xx responses raise UniRateAPIError (subclass of RuntimeError) with a
.status_code attribute:
| Status | Meaning |
|---|---|
| 400 | Invalid request parameters |
| 401 | Missing or invalid API key |
| 403 | Endpoint requires a Pro subscription (e.g. historical data) |
| 404 | Currency not found or no data available |
| 429 | Rate limit exceeded |
| 503 | Service unavailable |
Transport failures raise UniRateAPIError with status_code=None.
Related UniRate clients
If you want to call the API directly from a non-Haystack application, there are official clients in Python, Node.js, Go, Rust, Java, Ruby, PHP, .NET, and Swift, a LangChain integration, and an MCP server.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file haystack_unirate-0.1.0.tar.gz.
File metadata
- Download URL: haystack_unirate-0.1.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4f4bc53938b9250323833521084c69910128791f1b5be04dd12880de8cd0d8a
|
|
| MD5 |
20b9e347764d1a3f9d38635f39aa620a
|
|
| BLAKE2b-256 |
e4db666f39ac3596d44ab7c9418c3cae893217c308261721ebd3d276b5c4eb5e
|
Provenance
The following attestation bundles were made for haystack_unirate-0.1.0.tar.gz:
Publisher:
release.yml on UniRate-API/haystack-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
haystack_unirate-0.1.0.tar.gz -
Subject digest:
a4f4bc53938b9250323833521084c69910128791f1b5be04dd12880de8cd0d8a - Sigstore transparency entry: 2255450698
- Sigstore integration time:
-
Permalink:
UniRate-API/haystack-unirate@3cccd30105f62eab7cb6bee1a719f2fd2f558ebe -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/UniRate-API
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3cccd30105f62eab7cb6bee1a719f2fd2f558ebe -
Trigger Event:
push
-
Statement type:
File details
Details for the file haystack_unirate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: haystack_unirate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1f21d9e2f6f88900c94c2407cafc3f50afc24ec9107f6d7c070ee72114e9703
|
|
| MD5 |
5e2edaf6909eca296d6022d3e4090633
|
|
| BLAKE2b-256 |
6b82d3ad6dad4aeb3e263f0837b92174602f12e61c7fab3f208996f8cc6e5637
|
Provenance
The following attestation bundles were made for haystack_unirate-0.1.0-py3-none-any.whl:
Publisher:
release.yml on UniRate-API/haystack-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
haystack_unirate-0.1.0-py3-none-any.whl -
Subject digest:
d1f21d9e2f6f88900c94c2407cafc3f50afc24ec9107f6d7c070ee72114e9703 - Sigstore transparency entry: 2255450709
- Sigstore integration time:
-
Permalink:
UniRate-API/haystack-unirate@3cccd30105f62eab7cb6bee1a719f2fd2f558ebe -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/UniRate-API
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3cccd30105f62eab7cb6bee1a719f2fd2f558ebe -
Trigger Event:
push
-
Statement type: