Skip to content

UniRate-API/langchain-unirate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

langchain-unirate

PyPI License: MIT

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.

Other UniRate clients

UniRate ships official client libraries and framework integrations across the ecosystem. The repos below are all maintained under the UniRate-API org.

Get a free API key at unirateapi.com.

License

MIT — see LICENSE.

About

LangChain integration package for the UniRate currency-exchange API — wrapper utility + agent tool

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages