Registry / data / forex-python

forex-python

JSON →
library1.9.2pypypi✓ verified 35d 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.

datacommunication
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.920 runs
installs and imports cleanly · install 0.0s · import 0.602s · 22.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.3s · import 0.542s · 23MB
20MB installed
● package 20MB
Code
Verified usage

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

from forex_python.converter import CurrencyRates
from forex_python.bitcoin import BtcConverter
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 footguns
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.
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`.
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.
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
4
ahrefsbot
3
bytedance
2
script
1
Resources