tgherzog / wbgapi

Python module that makes using the World Bank's API a lot easier and more intuitive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in query for Worldwide Governance Indicators data

xxpeng opened this issue · comments

The query for any indicators in the Worldwide Governance Indicators database does not work due to error in the API address as shown below. The source id should be 3, instead of 2.

APIResponseError: APIError: JSON decoding error (https://api.worldbank.org/v2/en/sources/2/series/CC.PER.RNK.LOWER/country/NPL/time/all?per_page=1000&page=1&format=json)

Default database is WDI (db=2). To target a different database:

import wbgapi as wb
wb.data.DataFrame('CC.PER.RNK.LOWER', 'NPL', db=3)

or:

wb.db = 3 # set global option
wb.data.DataFrame('CC.PER.RNK.LOWER', 'NPL')

So the wb.data.DataFrame() could only request data from one database each time? If you have a list of indicators from multiple databases, you would have to parallel loop indicators and databases.

If you want multiple indicators from the same database, you can request them in one call. If they are in separate databases, you need to issue separate requests for each database.

To see why, look at the "lastupdated" column for just the first five available databases; they do not all update at the same time:

>>> wb.source.info()
id    name                               code      concepts  lastupdated
----  ---------------------------------  ------  ----------  -------------
1     Doing Business                     DBS              3  2021-08-18
2     World Development Indicators       WDI              3  2023-03-01
3     Worldwide Governance Indicators    WGI              3  2022-09-23
5     Subnational Malnutrition Database  SNM              3  2016-03-21
6     International Debt Statistics      IDS              4  2022-12-06

An indicator like SP.POP.TOTL (population) is included in 13 different World Bank databases. Which one did you intend to request?