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.
pip install currencyconverterVerified import paths — ran on the pinned version, not inferred.
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.
Always initialize with `CurrencyConverter(ECB_URL)` if you need recent historical rates. Be aware this requires an internet connection and will download the full historical dataset on initialization. Consider caching the downloaded file for performance in production environments.
If you need to handle dates outside the ECB's historical range, initialize the converter with `fallback_on_wrong_date=True` (e.g., `CurrencyConverter(fallback_on_wrong_date=True)`). This will use the earliest or latest available rate for dates before or after the data's bounds, respectively. Also, be aware that while it converts between non-EUR currencies, these conversions are implicitly routed through EUR.
To enable fallbacks for missing rates on specific dates, initialize the converter with `fallback_on_missing_rate=True`. You can also configure the method of fallback (e.g., `fallback_on_missing_rate_method='last_known'` or `'linear_interpolation'`).
Ensure the library is installed correctly using `pip install currencyconverter` and imported as `from currency_converter import CurrencyConverter` (note the underscore in the import, despite the package name not having one).
Verify that the currency code is a valid ISO 4217 three-letter code and is present in the list of available currencies (e.g., by checking `c.currencies` after initializing `CurrencyConverter`).
Provide a `date` within the available bounds for the currency (as indicated in the error message, or by checking `c.bounds`), or initialize the `CurrencyConverter` with `fallback_on_wrong_date=True` to use the closest available date.
No dependency data recorded yet.