A currency converter using the European Central Bank data.


Keywords
currency, exchange-rates, python
License
Apache-2.0
Install
pip install CurrencyConverter==0.17.20

Documentation

image

actions_ cratev_ crated_

This is a currency converter that uses historical rates against a reference currency (Euro). It is compatible with Python3.6+.

Currency data sources

The default source is the European Central Bank. This is the ECB historical rates for 42 currencies against the Euro since 1999. It can be downloaded here: eurofxref-hist.zip. The converter can use different sources as long as the format is the same.

Note that the currency converter does not query the API in real time, to avoid the overhead of the HTTP request. It uses embedded data in the library, which might not be up to date. If you need the latest data, please refer to the data section.

Installation

You can install directly after cloning:

Or use the Python package:

Command line tool

After installation, you should have currency_converter in your $PATH:

Python API

Create once the currency converter object:

Convert from EUR to USD using the last available rate:

Default target currency is EUR:

You can change the date of the rate:

Data

You can use your own currency file, as long as it has the same format (ECB):

Since the raw data is updated only once a day, it might be better to only download it once a day:

Fallbacks

Some rates are missing:

But we have a fallback mode for those, using a linear interpolation of the closest known rates, as long as you ask for a date within the currency date bounds:

The fallback method can be configured with the fallback_on_missing_rate_method parameter, which currently supports "linear_interpolation" and "last_known" values.

We also have a fallback mode for dates outside the currency bounds:

Decimal

If you need exact conversions, you can use the decimal option to use decimal.Decimal internally when parsing rates. This will slow down the load time by a factor 10 though.

Other attributes

  • bounds lets you know the first and last available date for each currency
  • currencies is a set containing all available currencies