Registry / data / forex-python

forex-python

JSON →
library1.9.2pypypi✓ verified 22d ago

forex-python (version 1.9.2) is an active Python library providing free foreign exchange rates and currency conversion functionalities. It supports listing all currency rates, retrieving Bitcoin prices, converting amounts between currencies, and accessing historical rates since 1999. The library's core data comes from theratesapi.com (sourced from the European Central Bank) for currency rates and CoinDesk for Bitcoin prices. It is regularly updated, though with an irregular release cadence, and is compatible with Python versions >=2.7 and <4, excluding 3.0-3.2.

pip install forex-python
INSTALL
IMPORT
SIG · FOREX-PYTHON
F
forex-python
datapythonv1.9.2
Install
2.3s avg
Import
346ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.356s · 22MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.336s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CurrencyRates
from forex_python.converter import CurrencyRates
BtcConverter
from forex_python.bitcoin import BtcConverter
CurrencyCodes
from forex_python.converter import CurrencyCodes

This quickstart demonstrates how to fetch current exchange rates, convert amounts, get Bitcoin prices, and retrieve currency symbols using the `forex-python` library. It emphasizes using `force_decimal=True` for accurate financial calculations.

from decimal import Decimal from forex_python.converter import CurrencyRates, CurrencyCodes from forex_python.bitcoin import BtcConverter # Initialize CurrencyRates with force_decimal for precision c = CurrencyRates(force_decimal=True) # Get conversion rate from USD to INR usd_to_inr_rate = c.get_rate('USD', 'INR') print(f"1 USD = {usd_to_inr_rate} INR") # Convert an amount amount_usd = Decimal('100.50') converted_amount_inr = c.convert('USD', 'INR', amount_usd) print(f"{amount_usd} USD = {converted_amount_inr} INR") # Get all latest rates for a base currency all_usd_rates = c.get_rates('USD') # print(f"All USD rates: {all_usd_rates}") # Uncomment to see all rates # Get Bitcoin price b = BtcConverter(force_decimal=True) btc_usd_price = b.get_latest_price('USD') print(f"1 BTC = {btc_usd_price} USD") # Get currency symbol codes = CurrencyCodes() gbp_symbol = codes.get_symbol('GBP') print(f"GBP symbol: {gbp_symbol}")
Debug
Known issues
breakingThe underlying API source used by `forex-python` has changed multiple times (e.g., to ratesapi.io in v1.0.0, and currently theratesapi.com). Older versions (especially pre-1.6) are prone to `RatesNotAvailableError` due to these upstream API changes or intermittent issues. Always use `forex-python>=1.6` to mitigate these issues and ensure compatibility with the current API.
fix
Upgrade to the latest version of `forex-python` (e.g., `pip install --upgrade forex-python`).
affects: <1.6
gotchaBy default, `forex-python` might return floating-point numbers for exchange rates and converted amounts, which can lead to precision errors in financial calculations. For accuracy, especially with monetary values, initialize `CurrencyRates` and `BtcConverter` with `force_decimal=True` and perform calculations using Python's `decimal.Decimal` type. This feature was introduced in version `0.3.2`.
fix
Initialize `CurrencyRates(force_decimal=True)` or `BtcConverter(force_decimal=True)` and use `decimal.Decimal` for amounts.
affects: <=1.9.2 (when `force_decimal` is not used)
gotchaThe currency exchange rates provided by `forex-python` are updated daily around 3 PM CET, as they are sourced from the European Central Bank. This means the rates are not 'real-time' in a sub-second or minute-by-minute sense, but rather daily snapshots. Users requiring instant, live exchange rates should consider dedicated real-time forex APIs.
fix
Understand that rates are daily, not live. For intra-day real-time data, use a different library or API service.
affects: All versions
gotchaThere have been user reports and GitHub issues regarding missing currencies or occasional discrepancies and incorrect conversion rates for specific currency pairs (e.g., AED, GBP to INR). While generally reliable, for critical applications, cross-validation with another source is advisable.
fix
For critical applications, cross-verify rates with an alternative data source, especially for less common currency pairs or if discrepancies are observed.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'forex_python'
The `forex-python` library is not installed in the Python environment being used, or there is a typo in the import statement.
fix
Install the library using pip: `pip install forex-python` or `pip3 install forex-python`. Ensure your virtual environment is activated if applicable.
forex_python.converter.RatesNotAvailableError: Currency Rates Source Not Ready
The external API (theratesapi.com) that `forex-python` relies on is temporarily unavailable, or the requested currency rates are not available for the specific date/time (e.g., requesting rates on a weekend or public holiday in Europe, or if there's an issue with the upstream data source).
fix
Check the status of `theratesapi.com`. Ensure your `forex-python` library is updated (`pip install --upgrade forex-python`). If requesting historical data, verify the date's validity. Implement `try-except` blocks to handle this specific error gracefully.
AttributeError: 'str' object has no attribute '_get_date_string'
This `AttributeError` often occurs when a method intended for an *instance* of `CurrencyRates` (or other classes like `BtcConverter`, `CurrencyCodes`) is incorrectly called directly on the *class* itself, rather than on an instantiated object.
fix
First, create an instance of the class before calling its methods. For example, instead of `CurrencyRates.get_rates(...)`, use `c = CurrencyRates(); c.get_rates(...)`.
KeyError: 'NPR' rate not available for Date latest
The requested currency code (e.g., 'NPR') is not available in the data returned by the API for the specified base currency or date, likely because the European Central Bank (the underlying data source) does not provide rates for that specific currency or pair.
fix
Verify that the requested currency pair is generally supported by the ECB rates. To prevent the error, use the dictionary's `.get(key, default_value)` method or check for key existence with `if key in dictionary:` before accessing it.
Upgrade
Version history
1.9.2latest on PyPI · released May 22, 2025
Audit
Dependencies
requestsrequiredUsed for making API calls to fetch exchange rates.
simplejsonrequiredUsed for JSON handling, especially for older Python versions or specific JSON features.
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
forex-python — pip install forex-python · libregistry