How to get exchange rates in Python
Read live and historical FX rates in Python with a few lines of code. No key to start, 10,000 calls a month once you sign up, and every response tells you how fresh the rate is.
The shortest path to exchange rates in Python is a GET request to /v1/latest/USD. You get back JSON with rates across the supported 31-currency catalog, with per-currency sources and effective_at metadata. No API key is required to make your first call.
/v1/latest/{base} returns rates for 31 currencies as JSON.sources[currency] and effective_at[currency] to describe the displayed currency; market_session describes the trading session.Your first call, no dependencies
You need nothing beyond the standard library. urllib.request handles a single call. To build a complete threshold monitor with saved state, see exchange-rate alerts in Python. Start with this request:
That runs without a key. Anonymous calls are capped per IP address, so for anything past a quick test you want a free key.
With requests and an API key
Most projects already use requests. Install requests, set EXCHANGERATE_API_KEY in your server environment, and pass the key as a bearer token:
A free key raises your limit to 10,000 calls a month at 12 requests a minute. The X-API-Key header works too, for platforms that cannot set Authorization.
Convert an amount
To convert rather than list rates, call /v1/convert. It returns the rate and the converted amount together:
Know how fresh a rate is
For a displayed currency, read sources[currency] and effective_at[currency]. The aggregate source field describes the least-fresh contributing data. source is the data class: live for aggregated spot, ecb_daily for the European Central Bank reference fix, fred_daily for the Federal Reserve daily series. market_session is open, weekend, or interbank_closed for a known non-weekend closure.
notice field.Read a single past day
Ask for any date back to 1999 by putting it in the path. The response adds is_forward_filled, which is true when no rate was published that day, such as a weekend or holiday:
For a full series across a date range in one call, use /v1/range with start_date and end_date. A separate guide covers that.