Querying World Bank Data

[1]:
from salamanca.data import WorldBank

salamanca provides a low-frills API into the World Bank REST interface. By default, salamanca saves a local copy of data in ~/.local/salamanca/data so that downloads are kept to a minimum.

[2]:
wb = WorldBank()

A number of commonly used indicators are provided out of the box.

[3]:
wb.exchange_rate().head()
[3]:
country date value
0 ABW 2020 NaN
1 ABW 2019 1.79
2 ABW 2018 1.79
3 ABW 2017 1.79
4 ABW 2016 1.79

Any WB indicator can be queried through a standard query() interface

[4]:
df = wb.query('SP.POP.TOTL', iso='USA')
df.head()
/Users/matthewgidden/work/iiasa/salamanca/salamanca/data.py:127: UserWarning: Can not cache queries with additional arguments
  warnings.warn('Can not cache queries with additional arguments')
[4]:
country date value
0 USA 2020 NaN
1 USA 2019 328239523.0
2 USA 2018 326687501.0
3 USA 2017 324985539.0
4 USA 2016 322941311.0

Advanced Usage

salamanca tries to support all available WB API query strings. See a list here.

An example of an advanced query is shown below.

[5]:
df = wb.query('DPANUSSPF', iso='ind;chn', date="2017M05:2017M07",
              frequency='M', use_cache=False)
df.head()
[5]:
country date value
0 CHN 2017M07 6.771143
1 CHN 2017M06 6.807023
2 CHN 2017M05 6.883304
3 IND 2017M07 64.438571
4 IND 2017M06 64.447364