⚡ Cloudflare Python Worker 📦 pip install CurrencyConverter
Live ECB data · Pyodide · Python Worker

CurrencyConverter

The real CurrencyConverter PyPI package, installed into a Cloudflare Python Worker via Pyodide. Powered by ECB exchange rate data bundled with the wheel.

📅 Rate date: Loading…  ·  🌍 currencies  ·  GitHub ↗
c.convert(amount, from_currency, to_currency) currency_converter v
CurrencyConverter Instance
Currencies
Data Date
Earliest Date
Latest Date
Currency Bounds (c.bounds)
Loading…
Historical Conversion

Convert using c.convert(amount, from, to, date=date(year, month, day))

🔄
Basic Conversion
Core convert() method — amount, source currency, target currency. Default target is EUR.
from currency_converter import CurrencyConverter

c = CurrencyConverter()

# Convert 100 USD → EUR
c.convert(100, 'USD', 'EUR')
# → 91.57 (varies by date)

# Default target is EUR
c.convert(100, 'GBP')
# → 118.3
📅
Historical Rates
Full ECB history since 1999. Pass a date= argument to query any past rate.
from datetime import date

c = CurrencyConverter()

c.convert(100, 'EUR', 'USD',
          date=date(2013, 3, 21))
# → 129.1

c.convert(100, 'GBP', 'EUR',
          date=date(2020, 1, 1))
# → 118.07
🌐
Data Sources
Use bundled data, the full ECB history, single-day ECB data, or your own CSV file in ECB format.
from currency_converter import (
    ECB_URL, SINGLE_DAY_ECB_URL,
    CurrencyConverter,
)
# Bundled (fastest, in this worker)
c = CurrencyConverter()

# Full history — live download
c = CurrencyConverter(ECB_URL)

# Today only — smallest download
c = CurrencyConverter(SINGLE_DAY_ECB_URL)
🛡️
Fallback Modes
Handle missing rates via linear interpolation or last-known rate. Handle out-of-bounds dates gracefully.
# Missing rate → interpolate
c = CurrencyConverter(
    fallback_on_missing_rate=True
)
c.convert(100, 'BGN',
          date=date(2010, 11, 21))
# → 51.12 (linear interpolation)

# Date before data → use earliest
c = CurrencyConverter(
    fallback_on_wrong_date=True)
c.convert(100, 'EUR', 'USD',
          date=date(1986, 2, 2))
🎯
Currencies & Bounds
Inspect the full set of supported currencies and the date range of data available for each one.
# Set of all supported currencies
c.currencies
# → {'USD', 'GBP', 'JPY', ...}

# First and last available date
first, last = c.bounds['USD']
# first → datetime.date(1999, 1, 4)
# last  → datetime.date(2024, xx, xx)

# Guard: check before converting
if 'AAA' not in c.currencies:
    raise ValueError("unsupported")
🔢
Decimal Precision
Use Python's decimal.Decimal for exact arithmetic — important for financial applications.
from datetime import date

# decimal=True slows load ~10x
# but gives exact arithmetic
c = CurrencyConverter(decimal=True)

c.convert(100, 'EUR', 'USD',
          date=date(2013, 3, 21))
# → Decimal('129.100')
# (not 129.09999999... float)
CodeName 1 unit → EUR1 EUR → units
Loading…