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.
Get all dataflow IDs from PDH.stat API
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
Plot time series population data using the Python plugin with PDH .Stat API

Last updated
Was this helpful?
