The real CurrencyConverter PyPI package, installed into a Cloudflare
Python Worker via Pyodide. Powered by
ECB
exchange rate data bundled with the wheel.
c.currencies and c.boundsConvert using c.convert(amount, from, to, date=date(year, month, day))
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
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
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)
# 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))
# 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.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)
c.convert(1, currency, 'EUR')| Code | Name | 1 unit → EUR | 1 EUR → units |
|---|---|---|---|
| Loading… | |||