currencyconverter 0.18.16


pip install currencyconverter

  Latest version

Released: Mar 24, 2026

Project Links

Meta
Author: Alex Prengère
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Programming Language
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy
https://raw.githubusercontent.com/alexprengere/currencyconverter/master/logo/cc3.png

actions cratev crated

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

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 --user

Or use the Python package:

$ pip install --user currencyconverter

Command 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-06

Python 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')

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

import os.path as op
import urllib.request
from datetime import date

from currency_converter import ECB_URL, CurrencyConverter

filename = f"ecb_{date.today():%Y%m%d}.zip"
if not op.isfile(filename):
    urllib.request.urlretrieve(ECB_URL, filename)
c = CurrencyConverter(filename)

Fallbacks

Some rates are missing:

>>> c.convert(100, 'BGN', date=date(2010, 11, 21))
Traceback (most recent call last):
RateNotFoundError: BGN has no rate for 2010-11-21

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:

>>> c = CurrencyConverter(fallback_on_missing_rate=True)
>>> c.convert(100, 'BGN', date=date(2010, 11, 21))
51.12...

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:

>>> c = CurrencyConverter()
>>> c.convert(100, 'EUR', 'USD', date=date(1986, 2, 2))
Traceback (most recent call last):
RateNotFoundError: 1986-02-02 not in USD bounds 1999-01-04/2016-04-29
>>>
>>> c = CurrencyConverter(fallback_on_wrong_date=True)
>>> c.convert(100, 'EUR', 'USD', date=date(1986, 2, 2)) # fallback to 1999-01-04
117.89...

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.

>>> c = CurrencyConverter(decimal=True)
>>> c.convert(100, 'EUR', 'USD', date=date(2013, 3, 21))
Decimal('129.100')

Other attributes

  • bounds lets you know the first and last available date for each currency

>>> first_date, last_date = c.bounds['USD']
>>> first_date
datetime.date(1999, 1, 4)
>>> last_date # doctest: +SKIP
datetime.date(2016, 11, 14)
  • currencies is a set containing all available currencies

>>> c.currencies # doctest: +SKIP
set(['SGD', 'CAD', 'SEK', 'GBP', ...
>>> 'AAA' in c.currencies
False
>>> c.convert(100, 'AAA')
Traceback (most recent call last):
ValueError: AAA is not a supported currency
0.18.16 Mar 24, 2026
0.18.15 Feb 20, 2026
0.18.14 Jan 21, 2026
0.18.13 Jan 06, 2026
0.18.12 Nov 04, 2025
0.18.11 Oct 22, 2025
0.18.10 Sep 25, 2025
0.18.9 Jul 28, 2025
0.18.8 Jul 01, 2025
0.18.7 Jun 09, 2025
0.18.6 May 12, 2025
0.18.5 Apr 04, 2025
0.18.4 Mar 07, 2025
0.18.3 Feb 12, 2025
0.18.2 Jan 06, 2025
0.18.1 Dec 12, 2024
0.18 Nov 22, 2024
0.17.34 Nov 06, 2024
0.17.33 Oct 21, 2024
0.17.32 Oct 01, 2024
0.17.31 Sep 14, 2024
0.17.30 Aug 26, 2024
0.17.29 Aug 12, 2024
0.17.28 Jul 30, 2024
0.17.27 Jul 19, 2024
0.17.26 Jul 12, 2024
0.17.25 Jul 06, 2024
0.17.24 Jun 27, 2024
0.17.23 Jun 05, 2024
0.17.22 May 23, 2024
0.17.21 May 02, 2024
0.17.20 Apr 09, 2024
0.17.19 Mar 16, 2024
0.17.18 Mar 14, 2024
0.17.17 Feb 20, 2024
0.17.16 Jan 30, 2024
0.17.15 Jan 03, 2024
0.17.14 Dec 19, 2023
0.17.13 Nov 08, 2023
0.17.12 Oct 24, 2023
0.17.11 Sep 28, 2023
0.17.10 Sep 06, 2023
0.17.9 Jun 26, 2023
0.17.8 Jun 16, 2023
0.17.7 Apr 18, 2023
0.17.6 Mar 23, 2023
0.17.5 Jan 16, 2023
0.17.4 Dec 22, 2022
0.17.3 Nov 22, 2022
0.17.2 Oct 13, 2022
0.17.1 Aug 28, 2022
0.17 Jul 19, 2022
0.16.13 Jun 28, 2022
0.16.12 May 06, 2022
0.16.11 Apr 01, 2022
0.16.10 Mar 14, 2022
0.16.9 Mar 01, 2022
0.16.8 Feb 10, 2022
0.16.7 Jan 14, 2022
0.16.6 Dec 21, 2021
0.16.5 Oct 12, 2021
0.16.4 Aug 19, 2021
0.16.3 Jul 05, 2021
0.16.2 Jun 14, 2021
0.16.1 May 18, 2021
0.16 Mar 10, 2021
0.15 Feb 15, 2021
0.14.4 Nov 03, 2020
0.14.3 Sep 25, 2020
0.14.2 Jun 10, 2020
0.14.1 Feb 24, 2020
0.14 Jan 09, 2020
0.13.11 Dec 10, 2019
0.13.10 Sep 19, 2019
0.13.9 Apr 25, 2019
0.13.8 Jan 10, 2019
0.13.7 Nov 06, 2018
0.13.6 Aug 08, 2018
0.13.5 Jun 13, 2018
0.13.3 Feb 19, 2018
0.13.2 Nov 23, 2017
0.13.1 Sep 06, 2017
0.13 Apr 09, 2017
0.12 Jan 24, 2017
0.11 Nov 29, 2016
0.10 Nov 02, 2016
0.8.1 May 10, 2016
0.8 May 03, 2016
0.7 Mar 14, 2016
0.5 Nov 12, 2015
0.4 Nov 12, 2015
0.3 Aug 13, 2015
0.2 Aug 12, 2015
No dependencies