In python you can convert currency using a simple package CurrencyConverter.
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:
$ python setup.py install --userOr use the Python package:
$ pip install --user currencyconverterCommand line tool
After installation, you should have currency_converter in your $PATH:
$ currency_converter 100 USD --to EUR
100.000 USD = 87.512 EUR on 2016-05-06Python API
Create once the currency converter object:
>>> from currency_converter import CurrencyConverter
>>> c = CurrencyConverter()Convert from EUR to USD using the last available rate:
>>> c.convert(100, 'EUR', 'USD') # doctest: +SKIP
137.5...Default target currency is EUR:
>>> c.convert(100, 'EUR')
100.0
>>> c.convert(100, 'USD') # doctest: +SKIP
72.67...You can change the date of the rate:
>>> from datetime import date # datetime works too
>>> c.convert(100, 'EUR', 'USD', date=date(2013, 3, 21))
129...Data
You can use your own currency file, as long as it has the same format (ECB):
from currency_converter import ECB_URL, SINGLE_DAY_ECB_URL
# Load the packaged data (might not be up to date)
c = CurrencyConverter()
# Download the full history, this will be up to date. Current value is:
# https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip
c = CurrencyConverter(ECB_URL)
# Dowload only the latest available day. Current value is:
# https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip
c = CurrencyConverter(SINGLE_DAY_ECB_URL)
# Load your custom file
c = CurrencyConverter('./path/to/currency/file.csv')