Sample code
Here are some worked examples of the PDH.stat API being used for various reasons. Full details of each implementation are available in the provided Github links.
Many of these tasks can be simplified through the PDH.stat API's suite of plugins.
Get all dataflow IDs from PDH.stat API
This Python script returns a list of all existing dataflowIDs. This can be useful for applications which need to check for new/updated dataflows.
import requests
from bs4 import BeautifulSoup
base_url = 'https://stats-nsi-stable.pacificdata.org/rest/'
def get_endpoints(base_url):
"""
Get the dataflowIDs of all existing dataflows in PDH .Stat API
:param base_url: the API's base URL
:return: list of strings
"""
endpoints = []
resources_url = base_url + 'dataflow/all/all/latest?detail=full'
resp = requests.get(resources_url, verify=False)
soup = BeautifulSoup(resp.text, 'xml')
for name in soup.findAll('Dataflow'):
endpoints.append(name['id'])
return endpoints
df_ids = get_endpoints(base_url)
print(df_ids)
# Output: ['DF_COMMODITY_PRICES', 'DF_CPI', 'DF_CURRENCIES', 'DF_EMPLOYED', 'DF_EMPRATES', 'DF_GFS', 'DF_HHEXP', 'DF_IMTS', 'DF_LABEMP', 'DF_NATIONAL_ACCOUNTS', 'DF_NEET', 'DF_NMDI', 'DF_NMDI_DEV', 'DF_NMDI_EDU', 'DF_NMDI_FIS', 'DF_NMDI_HEA', 'DF_NMDI_INF', 'DF_NMDI_OTH', 'DF_NMDI_POP', 'DF_OVERSEAS_VISITORS', 'DF_POCKET', 'DF_POP_COAST', 'DF_POP_DENSITY', 'DF_POP_PROJ', 'DF_SDG', 'DF_SDG_01', 'DF_SDG_02', 'DF_SDG_03', 'DF_SDG_04', 'DF_SDG_05', 'DF_SDG_06', 'DF_SDG_07', 'DF_SDG_08', 'DF_SDG_09', 'DF_SDG_10', 'DF_SDG_11', 'DF_SDG_12', 'DF_SDG_13', 'DF_SDG_14', 'DF_SDG_15', 'DF_SDG_16', 'DF_SDG_17', 'DF_UIS', 'DF_VITAL']Get basic metadata about a dataflow from PDH.stat API
This Python script returns a dictionary with the title, agencyId, version for a given dataflowId. This can be useful for applications which harvest from PDH.stat or simply need to display information about a dataset/dataflow. The function can be used iteratively for information on more than one dataflow.
Plot time series population data using the Python plugin with PDH .Stat API

This Python script demonstrates how the API can be accessed with the Python sdmx plugin. It makes a request for a filtered dataset of population projections for a specified number of countries. It then plots the results as a time series chart. It could be adapted to handle different countries, different time frames and other time series data too.
Last updated
Was this helpful?
