CurrencyConverter

0.18.16 · active · verified Sun Apr 12

CurrencyConverter is a Python library that provides historical currency exchange rates, primarily using data from the European Central Bank (ECB). It allows conversion between various currencies based on specified dates or the latest available historical rate. The library is compatible with Python 3.9+ and is actively maintained, with the current version being 0.18.16.

Warnings

Install

Imports

Quickstart

Initialize the `CurrencyConverter` object, optionally providing `ECB_URL` to download the latest historical rates. Then use the `convert()` method to perform conversions between an amount, source currency, target currency, and an optional specific date.

from currency_converter import CurrencyConverter, ECB_URL
from datetime import date
import os

# Initialize converter with the latest historical data from ECB (requires internet connection)
# This downloads the full history, which can take a moment.
# If you prefer to use the embedded data (might be outdated), use `c = CurrencyConverter()`
c = CurrencyConverter(ECB_URL)

# Convert 100 USD to EUR using the latest available rate
amount_eur = c.convert(100, 'USD', 'EUR')
print(f"100 USD = {amount_eur:.2f} EUR (latest historical rate)")

# Convert 50 EUR to GBP on a specific date
specific_date = date(2020, 1, 15)
amount_gbp = c.convert(50, 'EUR', 'GBP', date=specific_date)
print(f"50 EUR on {specific_date} = {amount_gbp:.2f} GBP")

# List available currencies (e.g., to check supported codes)
# print(c.currencies)

view raw JSON →