LangChain integration for the UniRate currency-exchange API — wrapper utility plus an agent tool for FX rate lookups and conversion.
Project description
langchain-unirate
LangChain integration for the UniRate API — drop-in currency-exchange tooling for LangChain agents and chains.
UniRate provides 593+ fiat, crypto, and commodity exchange rates. Latest rates and conversions are available on the free tier; historical and time-series endpoints require a Pro plan.
Why this package
There's no first-class FX tool in core LangChain — most tutorials show users
hand-rolling one against exchangerate-api.com or AlphaVantage. This package
gives you a typed, tested wrapper plus a ready-to-use BaseTool that an agent
can call directly via tool-calling.
Install
pip install langchain-unirate
Quick start
import os
os.environ["UNIRATE_API_KEY"] = "..." # https://unirateapi.com
from langchain_unirate import UniRateAPIWrapper, UniRateExchangeTool
wrapper = UniRateAPIWrapper()
# Direct API
print(wrapper.convert("USD", "EUR", amount=100)) # 92.5
print(wrapper.get_rate("USD", "GBP")) # 0.79
print(wrapper.get_supported_currencies()[:5])
# As an agent tool
tool = UniRateExchangeTool(api_wrapper=wrapper)
tool.invoke({"from_currency": "USD", "to_currency": "EUR", "amount": 100})
# -> "100 USD = 92.5 EUR (UniRate latest rate)"
Use with an agent
from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent
from langchain_unirate import UniRateAPIWrapper, UniRateExchangeTool
tool = UniRateExchangeTool(api_wrapper=UniRateAPIWrapper())
agent = create_react_agent(init_chat_model("openai:gpt-4o-mini"), tools=[tool])
agent.invoke({"messages": [("user", "How many euros is 250 dollars right now?")]})
API
UniRateAPIWrapper
| Method | Returns | Description |
|---|---|---|
get_rate(from_currency="USD", to_currency=None) |
float or dict[str, float] |
Latest rate; if to_currency is omitted, returns every supported target. |
convert(from_currency, to_currency, amount=1.0) |
float |
Convert amount at the latest rate. |
get_supported_currencies() |
list[str] |
All currency codes UniRate can convert between. |
run(from_currency, to_currency, amount=1.0) |
str |
Agent-friendly formatter wrapping convert. |
UniRateExchangeTool
BaseTool with a structured args_schema over (from_currency,
to_currency, amount). Compatible with any LangChain tool-calling pattern:
bind_tools(), create_react_agent, ToolNode, etc.
Configuration
| Constructor arg | Env var | Default |
|---|---|---|
unirate_api_key |
UNIRATE_API_KEY |
— (required) |
base_url |
— | https://api.unirateapi.com |
request_timeout |
— | 30 (seconds) |
Errors map cleanly to ValueError for 401 / 403 / 404 / 429; other
non-2xx responses raise requests.HTTPError.
Related UniRate clients
If you want to call the API directly from a non-Python application, there are official clients in Python, Node.js, Go, Rust, Java, Ruby, PHP, .NET, and Swift, as well as an MCP server for Claude Desktop and other MCP hosts.
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 langchain_unirate-0.1.0.tar.gz.
File metadata
- Download URL: langchain_unirate-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54bbbaeb08bedcf9b3286da2e8df32a2292db36c5a7622bef38d6eeef64095a7
|
|
| MD5 |
29cc2628f047d43215d31061b4af5877
|
|
| BLAKE2b-256 |
a748ea8f1797d866a21ec06a51511ade75d0894fc820c66df8eb83b9c2e5800e
|
Provenance
The following attestation bundles were made for langchain_unirate-0.1.0.tar.gz:
Publisher:
release.yml on UniRate-API/langchain-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_unirate-0.1.0.tar.gz -
Subject digest:
54bbbaeb08bedcf9b3286da2e8df32a2292db36c5a7622bef38d6eeef64095a7 - Sigstore transparency entry: 1417559334
- Sigstore integration time:
-
Permalink:
UniRate-API/langchain-unirate@9e2ddf25c9ba68948b7c1abcd04f130f96ef58f2 -
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@9e2ddf25c9ba68948b7c1abcd04f130f96ef58f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_unirate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_unirate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ced8708d9b821f2391449f3d39fcee64015dabaef81c54962dbaad6f9863552
|
|
| MD5 |
4d54a8af66243e5485b86723be7a319f
|
|
| BLAKE2b-256 |
4c310a812ef2d945973efb8b7dc21bfcb35824a5aec25a7b9b9c73989a0e3a50
|
Provenance
The following attestation bundles were made for langchain_unirate-0.1.0-py3-none-any.whl:
Publisher:
release.yml on UniRate-API/langchain-unirate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_unirate-0.1.0-py3-none-any.whl -
Subject digest:
9ced8708d9b821f2391449f3d39fcee64015dabaef81c54962dbaad6f9863552 - Sigstore transparency entry: 1417559340
- Sigstore integration time:
-
Permalink:
UniRate-API/langchain-unirate@9e2ddf25c9ba68948b7c1abcd04f130f96ef58f2 -
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@9e2ddf25c9ba68948b7c1abcd04f130f96ef58f2 -
Trigger Event:
push
-
Statement type: