Most tutorials on central bank data start with "get an API key". For the main policy rate you often do not need one. Five banks publish it at a plain URL, and each uses a different format: CSV, XML or JSON. This post reads all five with the standard library and lists what goes wrong.
What the script reads
| Bank | Series | Format | Endpoint |
|---|---|---|---|
| ECB | deposit facility rate, FM/D.U2.EUR.4F.KR.DFR.LEV | CSV (SDMX) | data-api.ecb.europa.eu |
| NBP (Poland) | reference rate | XML | static.nbp.pl/dane/stopy/stopy_procentowe.xml |
| Bank of Canada | V39079, target for the overnight rate | JSON (Valet) | bankofcanada.ca/valet |
| Bank of England | IUDBEDR, official Bank Rate | CSV | bankofengland.co.uk/boeapps/database |
| New York Fed | EFFR with the FOMC target range | JSON | markets.newyorkfed.org/api/rates |
The code
The full script is at the end of the post (policy_rates.py, Python 3.9+, standard library only). The parsing for each bank is a few lines. Two of them:
def ecb(): url = ("https://data-api.ecb.europa.eu/service/data/" "FM/D.U2.EUR.4F.KR.DFR.LEV?lastNObservations=1&format=csvdata") row = next(csv.DictReader(io.StringIO(get(url, "text/csv")))) return "ECB deposit facility", float(row["OBS_VALUE"]), row["TIME_PERIOD"], url def boc(): url = "https://www.bankofcanada.ca/valet/observations/V39079/json?recent=1" o = json.loads(get(url))["observations"][-1] return "BoC overnight target", float(o["V39079"]["v"]), o["d"], url The NBP file uses a decimal comma ("3,75"), so the value needs .replace(",", ".") before float(). The Bank of England returns every business day since the start date you ask for; the script takes the last line.
Output on 3 December 2026
bank / series rate % as of ECB deposit facility 2.50 2026-12-03 NBP reference 3.75 2026-03-05 BoC overnight target 2.50 2026-12-01 BoE Bank Rate 4.00 01 Dec 2026 Fed funds target 3.75-4.0 4.00 2026-12-01 The "as of" column means different things. For the ECB, Bank of Canada, Bank of England and the New York Fed it is the date of the latest observation, not the date of the last decision. For NBP it is the date the current rate took effect (obowiazuje_od), so it shows when the rate last changed. If you store these values, keep the source URL and the retrieval date next to each one.
What goes wrong
- Incomplete certificate chain. On the test machine,
urllibrefused the ECB endpoint withCERTIFICATE_VERIFY_FAILED, whilecurlfetched it. The server does not send its intermediate certificate; curl finds it on its own, Python does not. The script catches that one error and retries withcurl, which still verifies the certificate. Do not switch verification off. - Different meanings of "the rate". The ECB has three key rates, NBP has four, and the Fed has a target range plus a market rate (EFFR). Decide which one your page or model needs and name it. The script uses the ECB deposit facility rate, the NBP reference rate and the upper bound of the Fed range.
- Rate and observation dates differ. A rate unchanged for a quarter still has a fresh observation date in daily series. Do not read the date as "decided on".
- A file can be stale. The NBP file has a
data_publikacjiattribute. A cron job should check that it did not fall behind the bank's meeting calendar. - Banks that need a key. Banxico's SIE API needs a free token, and FRED needs a key. They are not in the script. Some other banks publish the rate only in an HTML table or a PDF; those need a scraper, and you should read the site's terms first.
Verifying against the source
After a run, open each bank's own rate page and compare the number. The script reads the same numbers, but a changed column name or series code can produce a wrong value without an error. Compare every run with a second reading from a different page for the banks whose rates you publish.
The same method, with more banks and a source and date on every row, is behind the table we publish at https://www.tasamira.com/es/estudios/tipos-interes-bancos-centrales/ (Spanish) and https://www.tasamira.com/pl/raporty/stopy-procentowe-bankow-centralnych/ (Polish), with the data downloadable as CSV.
The full script
"""Policy rates of five central banks from public endpoints, no API keys. Python 3.9+, standard library only.""" import csv, io, json, ssl, subprocess, urllib.error, urllib.request import xml.etree.ElementTree as ET UA = {"User-Agent": "Mozilla/5.0 (policy-rates-demo)"} def get(url, accept=None): h = dict(UA) if accept: h["Accept"] = accept try: with urllib.request.urlopen(urllib.request.Request(url, headers=h), timeout=30) as r: return r.read().decode("utf-8-sig") except (ssl.SSLError, urllib.error.URLError) as e: # Some servers (the ECB data API at the time of writing) send an # incomplete certificate chain. Browsers and curl fetch the missing # intermediate certificate; Python's urllib does not. Retry with curl # (still verifying the certificate) instead of switching verification off. if "CERTIFICATE_VERIFY_FAILED" not in str(e): raise cmd = ["curl", "-fsS", "--max-time", "30", "-A", UA["User-Agent"]] if accept: cmd += ["-H", "Accept: " + accept] return subprocess.run(cmd + [url], check=True, capture_output=True, text=True).stdout.lstrip("\ufeff") def ecb(): # Deposit facility rate, euro area; one row per day url = ("https://data-api.ecb.europa.eu/service/data/" "FM/D.U2.EUR.4F.KR.DFR.LEV?lastNObservations=1&format=csvdata") row = next(csv.DictReader(io.StringIO(get(url, "text/csv")))) return "ECB deposit facility", float(row["OBS_VALUE"]), row["TIME_PERIOD"], url def nbp(): # Reference rate; the file also lists lombard, deposit and rediscount rates url = "https://static.nbp.pl/dane/stopy/stopy_procentowe.xml" for p in ET.fromstring(get(url).encode()).iter("pozycja"): if p.get("id") == "ref": return ("NBP reference", float(p.get("oprocentowanie").replace(",", ".")), p.get("obowiazuje_od"), url) def boc(): # Bank of Canada Valet API, series V39079 = target for the overnight rate url = "https://www.bankofcanada.ca/valet/observations/V39079/json?recent=1" o = json.loads(get(url))["observations"][-1] return "BoC overnight target", float(o["V39079"]["v"]), o["d"], url def boe(): # Bank of England database, series IUDBEDR = official Bank Rate url = ("https://www.bankofengland.co.uk/boeapps/database/_iadb-fromshowcolumns.asp" "?csv.x=yes&Datefrom=01/Oct/2026&Dateto=now&SeriesCodes=IUDBEDR" "&CSVF=TN&UsingCodes=Y&VPD=Y&VFD=N") date, val = get(url).strip().splitlines()[-1].split(",") return "BoE Bank Rate", float(val), date, url def fed(): # New York Fed reference rates: EFFR plus the FOMC target range url = "https://markets.newyorkfed.org/api/rates/unsecured/effr/last/1.json" r = json.loads(get(url))["refRates"][0] return ("Fed funds target %s-%s" % (r["targetRateFrom"], r["targetRateTo"]), float(r["targetRateTo"]), r["effectiveDate"], url) if __name__ == "__main__": print("%-28s %6s %-12s" % ("bank / series", "rate %", "as of")) for f in (ecb, nbp, boc, boe, fed): try: name, rate, date, url = f() print("%-28s %6.2f %-12s" % (name, rate, date)) except Exception as e: # one bank down must not hide the others print("%-28s FAILED: %s" % (f.__name__, e)) Generated with AI tools and checked against the source pages on 3 December 2026.
Tasamira data team

