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, 50,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 for 31 currencies plus two freshness fields, source and market_session. No API key is required to make your first call.
/v1/latest/{base} returns rates for 31 currencies as JSON.source and market_session, so you know how fresh each rate is.Your first call, no dependencies
You need nothing beyond the standard library. urllib.request handles a single call:
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. Pass your key as a bearer token:
A free key raises your limit to 50,000 calls a month at 30 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
Two fields on every response tell you what you are looking at. 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 says whether the FX day is open, weekend, or between sessions.
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.