Streamlit integration for the UniRate API — live exchange rates, currency conversion, and VAT rates with automatic st.cache_data / st.cache_resource caching built in.
pip install streamlit-unirateimport streamlit as st
import streamlit_unirate as ur
# List currencies (cached 1 h)
currencies = ur.list_currencies()
from_cur = st.selectbox("From", currencies)
to_cur = st.selectbox("To", currencies)
amount = st.number_input("Amount", value=100.0)
if st.button("Convert"):
result = ur.convert(to_cur, amount, from_cur)
st.metric(f"{amount} {from_cur} →", f"{result:.4f} {to_cur}")Set UNIRATE_API_KEY in .streamlit/secrets.toml (preferred) or as an environment variable:
# .streamlit/secrets.toml
UNIRATE_API_KEY = "your_api_key_here"UNIRATE_API_KEY=your_key streamlit run app.pyGet a free key at unirateapi.com.
All functions use Streamlit's caching automatically — no extra decorators needed.
Returns the underlying unirate.UnirateClient singleton (cached via @st.cache_resource). Use this when you need direct access to Pro endpoints such as historical rates or time series.
client = ur.get_client()
data = client.get_time_series("2025-01-01", "2025-01-31", base_currency="USD")Current exchange rate. Cached for 5 minutes.
rate = ur.get_rate("USD", "EUR") # → 0.9214 (float)
all_rates = ur.get_rate("USD") # → {"EUR": 0.92, "GBP": 0.79, ...}Convert an amount. Cached for 5 minutes.
eur = ur.convert("EUR", 250.0, "USD") # → 230.35All supported currency codes. Cached for 1 hour.
codes = ur.list_currencies() # → ["AED", "AFN", ..., "ZWL"]VAT rates for all countries or a single ISO-3166 country code. Cached for 24 hours.
all_vat = ur.get_vat_rates()
de_vat = ur.get_vat_rates("DE")All functions raise exceptions from unirate.exceptions:
| Exception | Cause |
|---|---|
AuthenticationError |
Missing or invalid API key |
RateLimitError |
Free-tier rate limit exceeded |
InvalidCurrencyError |
Unknown currency code |
APIError |
Other API error (check .status_code) |
from unirate.exceptions import RateLimitError, AuthenticationError
import streamlit_unirate as ur
try:
rate = ur.get_rate("USD", "EUR")
except AuthenticationError:
st.error("Check your UNIRATE_API_KEY.")
except RateLimitError:
st.warning("Rate limit hit — try again in a moment.")Other UniRate integrations: Python · Node.js · Go · Rust · Ruby · PHP · Java · Swift · .NET · FastAPI · Flask · Django REST · Wagtail · Next.js · Nuxt · SvelteKit · React · Vue · Angular · Remix · NestJS · LangChain (Python) · LangChain.js · Astro · Eleventy · Hugo · Jekyll · Strapi · Directus · Medusa · MCP Server · CLI
MIT — see LICENSE.