Client library

Exchange Rates in Python Using The Global Exchange Rates API

Published Updated 2 min read

The Global Exchange Rates API now has an official Python client, published on PyPI: https://pypi.org/project/global-exchange-rates/.

It supports both sync and async usage and is ideal for developers who need to fetch currency exchange rates in Python, convert amounts, or integrate official central bank data in finance-related apps.

Installation

Code
pip install global-exchange-rates

Example: Get Latest Exchange Rates

Code
from global_exchange_rates import GlobalExchangeRates

client = GlobalExchangeRates(api_key="YOUR_API_KEY")

rates = client.get_latest(
    base_currency="EUR",
    currencies=["USD", "GBP", "JPY"]
)

print(f"1 EUR = {rates.exchange_rates['USD']} USD")

Async usage is also supported via async with:

Code
import asyncio
from global_exchange_rates import GlobalExchangeRates

async def main():
    async with GlobalExchangeRates(api_key="YOUR_API_KEY") as client:
        rates = await client._get_latest_async(base_currency="EUR", currencies=["USD"])
        print(f"1 EUR = {rates.exchange_rates['USD']} USD")

asyncio.run(main())

Example: Convert an Amount

The client can also convert an amount directly using the official rates:

Code
conversion = client.convert(
    amount=100.0,
    base_currency="EUR",
    to_currencies=["USD", "GBP"]
)

print(f"100 EUR = {conversion.conversions['USD']:.2f} USD")

Example: Historical Rates

Retrieve the official rates for a specific date, and optionally from a specific provider such as the ECB:

Code
from datetime import date

historical = client.get_historical(
    date_value=date(2025, 1, 1),
    base_currency="EUR",
    currencies=["USD"]
)

print(historical.exchange_rates["USD"])

You can also list the available institutions and currency codes with get_providers() and get_currencies().

Handling Errors

API errors are raised as ApiException, which carries the HTTP status and message:

Code
from global_exchange_rates import ApiException

try:
    rates = client.get_latest(base_currency="EUR", currencies=["USD"])
except ApiException as e:
    print(f"API error {e.status_code}: {e}")

Calling the API Directly

If you prefer not to add a dependency, you can call the API directly with requests. The key is passed as the subscription-key query parameter:

Code
import requests

resp = requests.get(
    "https://api.globalexchangerates.org/v1/latest",
    params={"subscription-key": "YOUR_API_KEY", "base": "EUR"}
)
data = resp.json()

print(data["exchangeRates"]["USD"])

Keeping the Rates Up to Date

Official rates are published once per business day, so running your script on a schedule (for example via cron or Windows Task Scheduler) is usually enough to keep your data current.

The same official rates are available in other tools — see our guides for Power BI and Google Sheets. The full method reference is in the API documentation. If you don’t have an API key yet, you can get one on the get-started page, with official rates from central banks and tax authorities worldwide.


Let us know if you use the library in a project or have feature requests—we’re always interested in improving things for Python developers.