Allows downloading data from the ECB's Statistical Data Warehouse (SDW)
Project description
A Basic SDW API
This package provides a basic API for the ECB's Statistical Data Warehouse (SDW).
In its current version, a few features are still missing. Nonetheless, the package already allows for downloading data seamlessly. An option allows saving the downloaded data directly into a .xlsx spreadsheet.
1.0 Basic Functionality
1.1 Installation
The package is available via pip. To install the SDW_API simply run pip install sdw-api in your command prompt.
1.2 Downloading Data
The package consists of one main class called SDW_API, which handles the data download and basic data treatment automatically. Once the package is downloaded, it can be imported using the following statement:
from sdw_api import SDW_API
The SDW_API class takes the following input arguments:
SDW_API(ticker_list, start=None, end=None, outpath=None, filename=None, target_freq=None,method=None)
They can be separated into two groups:
- Required/Positional arguments:
ticker_list: A python list containing the data series tickers or labels. These are equivalent to the ones used on the SDW website.
- Keyword Arguments:
start: This argument can be used, if a start date is to be set. The start date has to be inYYYY-MM-DDformat. If this argument is specified, only data with a time stamp that is more recent than the start date is retrieved. If the argument isNone, the entire available history will be downloaded.end: This argument can be used, if an end date is to be set. The end date has to be inYYYY-MM-DDformat. If this argument is specified, only data with a time stamp that is older than the end date is retrieved.outpath: If the resulting date is to be saved as.xlsxan output path can be specified. This argument sets the directory where the data is to be saved.filename: This argument allows to specify a unique filename for the output file. If neitheroutpathnorfilenameare set, the output file is not saved.target_freq: This setting allows for defining a desired output frequency of the final DataFrame or spreadsheet. The class automatically detects the data frequency of the individual data series inticker_list. Ifticker_listcontains time series at monthly as well as quarterly frequency, the highest frequency is assumed as a default. In this example, the output DataFrame will thus be at monthly frequency. In this case, settingtarget_freqto "Q" overwrites the default. The final DataFrame is then at quarterly frequency.method: Iftarget_freqis set to "Q", but theticker_listalso contains time series at monthly frequency, this option allows for setting an aggregation method for the time series at higher frequency. At the moment, only the average is implemented, which is also the default option.
2.0 Example
Let's assume we want to download Euro area (EA) HICP excluding food and energy ('ICP.M.U2.Y.XEF000.3.INX'), EA GDP ('MNA.Q.Y.I8.W2.S1.S1.B.B1GQ._Z._Z._Z.EUR.LR.N'), the historical close of the EONIA at monthly frequency ('FM.M.U2.EUR.4F.MM.EONIA.HSTA'), and EA total employment in hours worked ('ENA.Q.Y.I8.W2.S1.S1._Z.EMP._Z._T._Z.HW._Z.N') over from January 2000 (i.e. '2000-01-01') until now.
Assuming the package is imported, let's first download the data at monthly frequency:
# set the tickers to be downloaded
ticker_list = ['ICP.M.U2.Y.XEF000.3.INX',
'MNA.Q.Y.I8.W2.S1.S1.B.B1GQ._Z._Z._Z.EUR.LR.N',
'FM.M.U2.EUR.4F.MM.EONIA.HSTA',
'ENA.Q.Y.I8.W2.S1.S1._Z.EMP._Z._T._Z.HW._Z.N']
# set a start date
start = '2000-01-01'
# initialize the API
example = SDW_API(ticker_list, start=start)
# download the data and compose DataFrame
example()
# access the output data
example.data
The head of the resulting DataFrame looks something like this:
| ICP.M.U2.Y.XEF000.3.INX | MNA.Q.Y.I8.W2.S1.S1.B.B1GQ._Z._Z._Z.EUR.LR.N | FM.M.U2.EUR.4F.MM.EONIA.HSTA | ENA.Q.Y.I8.W2.S1.S1._Z.EMP._Z._T._Z.HW._Z.N | |
|---|---|---|---|---|
| 2000-01-31 00:00:00 | 79.8723 | nan | 3.04286 | nan |
| 2000-02-29 00:00:00 | 79.8981 | nan | 3.27571 | nan |
| 2000-03-31 00:00:00 | 79.9401 | 2.22607e+06 | 3.51043 | 5.83027e+07 |
| 2000-04-30 00:00:00 | 79.9912 | nan | 3.685 | nan |
| 2000-05-31 00:00:00 | 80.0094 | nan | 3.92 | nan |
To generate output data at quarterly frequency instead, the following commands can be used:
# set the tickers to be downloaded
ticker_list = ['ICP.M.U2.Y.XEF000.3.INX',
'MNA.Q.Y.I8.W2.S1.S1.B.B1GQ._Z._Z._Z.EUR.LR.N',
'FM.M.U2.EUR.4F.MM.EONIA.HSTA',
'ENA.Q.Y.I8.W2.S1.S1._Z.EMP._Z._T._Z.HW._Z.N']
# set a start date
start = '2000-01-01'
target_freq = 'Q'
# initialize the API
example = SDW_API(ticker_list, start=start, target_freq=target_freq)
# download the data and compose DataFrame
example()
# access the output data
example.data
The monthly series have now been aggregated to quarterly frequency automatically:
| ICP.M.U2.Y.XEF000.3.INX | MNA.Q.Y.I8.W2.S1.S1.B.B1GQ._Z._Z._Z.EUR.LR.N | FM.M.U2.EUR.4F.MM.EONIA.HSTA | ENA.Q.Y.I8.W2.S1.S1._Z.EMP._Z._T._Z.HW._Z.N | |
|---|---|---|---|---|
| 2000-03-31 00:00:00 | 79.9035 | 2.22607e+06 | 3.27634 | 5.83027e+07 |
| 2000-06-30 00:00:00 | 80.0513 | 2.24645e+06 | 3.96652 | 5.85199e+07 |
| 2000-09-30 00:00:00 | 80.2987 | 2.2588e+06 | 4.43939 | 5.87186e+07 |
| 2000-12-31 00:00:00 | 80.5968 | 2.27377e+06 | 4.80622 | 5.89292e+07 |
| 2001-03-31 00:00:00 | 80.7685 | 2.29697e+06 | 4.84326 | 5.90698e+07 |
3.0 Features coming soon:
- more aggregation methods
- support for more data frequencies
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SDW_API-0.1.3.tar.gz.
File metadata
- Download URL: SDW_API-0.1.3.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a19be905b90c8ed18889e1b95d91a99195fd18abdf7d90189c3395cb9acf4ef9
|
|
| MD5 |
75ce5e8f54dcd38f4ab25a6cd3e82d89
|
|
| BLAKE2b-256 |
94d8dff3f436684ed044d4e636b6c1c5a2d779aa17967927deafef8d34f66dd7
|
File details
Details for the file SDW_API-0.1.3-py3-none-any.whl.
File metadata
- Download URL: SDW_API-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbffebe766f38a1c6cb36b017ede89874588640e536f222d79268ac265ca8e14
|
|
| MD5 |
bfe34d336ec88d6db0f4528d1abcb2f5
|
|
| BLAKE2b-256 |
b2274af9ea79267794db3c81aa03c3745c8822b02466f99834386b0a00c563e0
|