Skip to main content

Streamlit integration for the UniRate currency-exchange API — cached helpers with st.cache_resource and st.cache_data support.

Project description

streamlit-unirate

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.

PyPI Python License: MIT CI

Installation

pip install streamlit-unirate

Quick start

import 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}")

API key

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.py

Get a free key at unirateapi.com.

API reference

All functions use Streamlit's caching automatically — no extra decorators needed.

get_client(api_key=None, base_url=None)

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")

get_rate(from_currency="USD", to_currency=None)float | dict

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(to_currency, amount=1.0, from_currency="USD")float

Convert an amount. Cached for 5 minutes.

eur = ur.convert("EUR", 250.0, "USD")     # → 230.35

list_currencies()list[str]

All supported currency codes. Cached for 1 hour.

codes = ur.list_currencies()              # → ["AED", "AFN", ..., "ZWL"]

get_vat_rates(country=None)dict

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")

Error handling

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.")

Related UniRate clients

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

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_unirate-0.1.0.tar.gz (129.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_unirate-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_unirate-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_unirate-0.1.0.tar.gz
  • Upload date:
  • Size: 129.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for streamlit_unirate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c76e08f1015503f33bb285357bd06610f4f64f5262d905e8e4acdc6c30ff926
MD5 a10b0f59aa5afd509a9732f4b40eee03
BLAKE2b-256 a1de3c7d5b7ea5c28b1337730441f768c76a6e3c5c4ab8b7516a83f7dd59f5c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_unirate-0.1.0.tar.gz:

Publisher: release.yml on UniRate-API/streamlit-unirate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_unirate-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_unirate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81fc85b08fcdfdeb2e55020bcd68cf5099951097c0e6e82d7d6523fdc80a4e22
MD5 d7ef7188a34c792b078d341b84ef8171
BLAKE2b-256 adaae90a0ca71dd1acd56b5b68fd5ed9a62a0ddee1bde24cd5bbc85b6161e555

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_unirate-0.1.0-py3-none-any.whl:

Publisher: release.yml on UniRate-API/streamlit-unirate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page