Easy Access to ECB Data, in Python

Introducing ecbdata — a simple API for ECB data retrieval

Luca Mingarelli
3 min readApr 16, 2024
[Source: Image from ECB]

The European Central Bank (ECB) has recently launched its new Data Portal, opening a treasure trove of economic and financial data for researchers and analysts! The Data Portal replaces the older Statistical Data Warehouse which is now discontinued.

This brief article will guide you through the minimal steps necessary to retrieve data in Python from the ECB’s Data Portal, with the new ecbdata library.

The ecbdata library is a Python package designed to empower you to automate data downloads from the ECB Data Portal. With just a few lines of code, you can effortlessly access the latest economic indicators, banking statistics, and more, directly within your Python environment.

To get started, install the library with pip:

pip install ecbdata

As an example, let’s retrieve and plot the inflation rate for the euro area from the beginning of 2010. First, we search for ‘inflation rate’ on the portal’s main page. The first result gives us the Harmonised Index of Consumer Prices (HICP) in Euro area (changing composition), of which we want to retrieve the associated series_key, in this case ICP.M.U2.N.000000.4.ANR.

Then, in Python we can simply retrieve the associated series as it follows:

from ecbdata import ecbdata

df = ecbdata.get_series('ICP.M.U2.N.000000.4.ANR',
start='2010-01')

It is now simple to plot the series:

import pandas as pd
import matplotlib.pyplot as plt

df.TIME_PERIOD = pd.to_datetime(df.TIME_PERIOD)
df = df.set_index('TIME_PERIOD')
df.OBS_VALUE.plot()
plt.show()
HICP Euro Area Inflation [Source: Author’s image]

More options are available to cater for individual needs in the data query. In particular, the ecbdata.get_series method accepts the following parameters:

series_key: The series key for the data to be retrieved. In the example above this is “ICP.M.U2.N.000000.4.ANR”.

start and end: It is possible to define a start and end date for which observations are to be returned. The format will vary depending on the frequency: YYYY for annual data (e.g. 2020); YYYY-S[1–2] for semi-annual data (e.g. 2020-S1); YYYY-Q[1–4] for quarterly data (e.g. 2020-Q1); YYYY-MM for monthly data (e.g. 2020–01); YYYY-W[01–53] for weekly data (e.g. 2020-W01); YYYY-MM-DD for daily data (e.g. 2020–01–01).

detail: Possible options are as follows: full (default): both data and Attributes will be returned; dataonly: Attributes will be excluded from the returned message; serieskeysonly: only the Time series will be returned, excluding Attributes and Observations (this is useful to list time series matching a certain query without returning the actual data); nodata: Time series will be returned, including Attributes, but Observations will not.

updatedafter: Expects a percent-encoded ISO 8601 timestamp. This retrieves the latest version of changed values in the database after a certain point in time (i.e. updates and revisions). For example, the percent-encoded representation for 2009–05–15T14:15:00+01:00 would be: 2009–05–15T14%3A15%3A00%2B01%3A00. Developers who update their local databases with data stored in the ECB Data Portal should make use of the updatedafter parameter, as this will significantly improve performance. Instead of systematically downloading data that have not changed, you will only receive the changes that were made in the database after you last performed the same query. If nothing has changed, the server will respond with a HTTP 304 response code.

firstnobservations and lastnobservations: returns the first or last n observations.

includehistory: This allows to see how the data have evolved over time (i.e. new data releases, revisions, deletions). Possible options are: false (default): only the version currently in production will be returned. true: the version currently in production and all previous versions will be returned.

References

[1] Disclaimer: The author of this article is also the author of ecbdata.

[2] The library is Open Source: contributions are welcome!

[3] ECB Data Portal

[4] The library wraps the ECB Data Portal RESTful API.

--

--