|
2 | 2 | A Python 2/3 wrapper for the World Bank API
|
3 | 3 | See World Bank [Developer Information](https://datahelpdesk.worldbank.org/knowledgebase/topics/125589-developer-information) to get information on the raw API
|
4 | 4 |
|
5 |
| -## Classes |
6 |
| -Classes are used to store the data returned by the API and the `classmethods` and Instance Methods are used to fetch data from the API |
7 |
| - |
8 |
| -- [Catalog](#catalog) |
9 |
| -- [City](#city) |
10 |
| -- [Country](#country) |
11 |
| -- [CountryIndicator](#countryindicator) |
12 |
| -- [IncomeLevel](#incomelevel) |
13 |
| -- [Indicator](#indicator) |
14 |
| -- [LendingType](#lendingtype) |
15 |
| -- [Region](#region) |
16 |
| - - [AdminRegion](#adminregion) |
17 |
| -- [Source](#source) |
18 |
| -- [Topic](#topic) |
19 |
| - |
20 |
| - |
21 |
| -### Catalog |
22 |
| -The Data Catalog API provides programmatic access to the list of datasets in the [World Bank’s Open Data Catalog](https://data.worldbank.org/data-catalog/) with associated metadata. Each metatype returned is added to the instance as an attribute. |
23 |
| - |
24 |
| -#### Instance Attributes |
25 |
| -- id |
26 |
| - |
27 |
| -See [World Bank Catalog API](https://datahelpdesk.worldbank.org/knowledgebase/articles/902049-data-catalog-api) for more details |
28 |
| - |
29 |
| -### City |
30 |
| -A city in a [country](#country). A `country`'s `capital` is a `City` instance |
31 |
| - |
32 |
| -#### Instance Attributes |
33 |
| -- name |
34 |
| -- latitude |
35 |
| -- longitude |
36 |
| - |
37 |
| -#### Instance Methods |
38 |
| -- get(page=1, per_page=50] |
39 |
| - |
40 |
| -### Country |
41 |
| -A country existing in the World Bank database |
42 |
| - |
43 |
| -#### Instance Attributes |
44 |
| -- id |
45 |
| -- name |
46 |
| -- iso_code |
47 |
| -- region - a [Region](#region) instance |
48 |
| -- admin_region - an [AdminRegion](#adminregion) instance |
49 |
| -- income_level - an [IncomeLevel](#incomelevel) instance |
50 |
| -- lending_type - a [LendingType](#lendingtype) instance |
51 |
| -- capital - A [City](#city) instance |
52 |
| - |
53 |
| -#### Instance Methods |
54 |
| -- get(iso_code=None, page=1, per_page=50] |
55 |
| - - If an iso_code is not provided, returns a list of all [Countries](#country). If an iso_code is provided, returns a [Country](#country) instance of the given iso_code. |
56 |
| -- by_income_level(income_level] |
57 |
| - - Returns [Countries](#country) that all have a given [IncomeLevel](#incomelevel) |
58 |
| -- by_lending_type(lending_type] |
59 |
| - - Returns [Countries](#country) that all have a given [LendingType](#lendingtype) |
60 |
| - |
61 |
| -See the [World Bank Country API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898590-api-country-queries) for more details |
62 |
| - |
63 |
| -### CountryIndicator |
64 |
| -A measure of an [Indicator](#indicator) for a given country for a given year |
65 |
| - |
66 |
| -#### Instance Attributes |
67 |
| -- Indicator - an instance of an [Indicator](#indicator) |
68 |
| -- country |
69 |
| - - id |
70 |
| - - name |
71 |
| -- year - year when the measure of the indicator occurred |
72 |
| -- value - floating point number |
73 |
| -- decimal - a measure of precision of the returned value |
74 |
| - |
75 |
| -#### Instance Methods |
76 |
| -- get(indicator, country='all', page=1, per_page=50, start=None, end=None] |
77 |
| - - Returns instances of `CountryIndicator` for a given [Indicator](#indicator). If a `start` year and `end` year are provided, returns `CountryIndicators` where `start` >= year <= `end`. |
78 |
| - - If a country is provided, only returns `CountryIndicators` for the given country. If a country is not provided, returns `CountryIndicators` for the [Indicator](#indicator) for all countries. |
79 |
| - |
80 |
| -See the [World Bank Indicator API](See https://datahelpdesk.worldbank.org/knowledgebase/articles/898599-api-indicator-queries) for more details |
81 |
| - |
82 |
| - |
83 |
| -### IncomeLevel |
84 |
| -Income levels show the income category of a particular country as identified by the World Bank. For more information see the [World Bank Country and Lending Groups](https://datahelpdesk.worldbank.org/knowledgebase/articles/906519-world-bank-country-and-lending-groups) page. |
85 |
| - |
86 |
| -#### Instance Attributes |
87 |
| -- id |
88 |
| -- name |
89 | 5 |
|
90 |
| -#### Instance Methods |
91 |
| -- get(page=1, per_page=50] |
92 |
| - - Returns a list of all [IncomeLevels](#incomelevel) |
| 6 | +## Quickstart |
| 7 | +```python |
| 8 | +from worldbank import api as wb |
| 9 | + |
| 10 | +summary, indicators = wb.Indicator.get() |
| 11 | +summary, country_indicators = wb.CountryIndicator.get(indicators[0]) |
| 12 | +summary, countries = wb.Country.get() |
| 13 | +summary, lending_types = wb.LendingType.get() |
| 14 | +summary, topics = wb.Topic.get() |
| 15 | +summary, sources = wb.Source.get() |
| 16 | +summary, income_levels = wb.IncomeLevel.get() |
| 17 | +summary, indicators = wb.Indicator.get() |
| 18 | +summary, countries = wb.Country.by_income_level(income_level=income_levels[0]) |
| 19 | +summary, country = wb.Country.by_lending_type(lending_types[0]) |
| 20 | +summary, indicators = wb.Indicator.by_source(sources[0]) |
| 21 | +summary, indicators = wb.Indicator.by_topic(topics[0]) |
| 22 | +summary, country_indicators = wb.CountryIndicator.get(indicators[0]) |
| 23 | +``` |
93 | 24 |
|
94 |
| -See the [World Bank Income Level API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898596-api-income-level-queries) for more details. |
95 |
| - |
96 |
| -### Indicator |
97 |
| - |
98 |
| -#### Instance Attributes |
99 |
| -- id |
100 |
| -- name |
101 |
| -- source - A [Source](#source) instance |
102 |
| -- topics - A list of [Topics](#topic) |
103 |
| -- source_note - a description of the indicator by the `source_organization` |
104 |
| -- source_organization - The name of the organization providing the data for the indicator |
105 |
| - |
106 |
| -#### Instance Methods |
107 |
| -- get(indicator_id=None, page=1, per_page=50] |
108 |
| - - If a indicator_id is provided, returns a single [Indicator](#indicator). If an indicator_id is not provided, then all [Indicators](#indicator) will be returned based on the `page` and `per_page` parameter |
109 |
| -- by_source(source, page=1, per_page=50] |
110 |
| - - Returns [Indicators](#indicator) that all come from the [Source](#source) |
111 |
| -- by_topic(topic] |
112 |
| - - Returns [Indicators](#indicator) that all have a given [Topic](#topic) |
113 |
| - |
114 |
| -See the [World Bank Indicator API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898599-api-indicator-queries) for more details. |
115 |
| - |
116 |
| -### LendingType |
117 |
| -The World Bank classified countries according to the type of lending they are eligible for through the World Bank. For more information see the [World Bank Country and Lending Groups](https://datahelpdesk.worldbank.org/knowledgebase/articles/906519-world-bank-country-and-lending-groups) page. |
118 |
| - |
119 |
| -#### Instance Attributes |
120 |
| -- id |
121 |
| -- name |
122 |
| - |
123 |
| -#### Instance Methods |
124 |
| -- get(page=1, per_page=50] |
125 |
| - - Returns a list of all [LendingTypes](#lendingtypes) |
126 |
| - |
127 |
| -See the [World Bank Lending Type API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898608-api-lending-type-queries) for more details |
128 |
| - |
129 |
| -### Region |
130 |
| - |
131 |
| -#### Instance Attributes |
132 |
| -- id |
133 |
| -- name |
134 |
| - |
135 |
| -#### AdminRegion |
136 |
| - |
137 |
| -#### Instance Attributes |
138 |
| -- id |
139 |
| -- name |
140 |
| - |
141 |
| -### Source |
142 |
| -An organization that provides data as [CountryIndicators](#countryindicator) for a given number of [Indicators](#indicator) |
143 |
| - |
144 |
| -#### Instance Attributes |
145 |
| -- id |
146 |
| -- name |
147 |
| -- description |
148 |
| -- url |
149 |
| - |
150 |
| -#### Instance Methods |
151 |
| -- get(page=1, per_page=50] |
152 |
| - - Returns a list of all [Sources](#source) |
153 |
| - |
154 |
| -See the [World Bank Source API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898587-api-catalog-source-queries) for more details |
155 |
| - |
156 |
| -### Topic |
157 |
| -A high-level category that all [Indicators](#indicator) are mapped to |
158 |
| - |
159 |
| -#### Instance Attributes |
160 |
| -- id |
161 |
| -- name |
162 |
| -- note |
163 |
| - |
164 |
| -#### Instance Methods |
165 |
| -- get(page=1, per_page=50] |
166 |
| - - Returns a list of all [Topics](#topic) |
| 25 | +Classes are used to store the data returned by the API and the `classmethods` and Instance Methods are used to fetch data from the API |
167 | 26 |
|
168 |
| -See the [World Bank Topic API](https://datahelpdesk.worldbank.org/knowledgebase/articles/898611-api-topic-queries) for more details |
| 27 | +* Catalog |
| 28 | +* City |
| 29 | +* Country |
| 30 | +* CountryIndicator |
| 31 | +* IncomeLevel |
| 32 | +* Indicator |
| 33 | +* LendingType |
| 34 | +* Region |
| 35 | + * AdminRegion |
| 36 | +* Source |
| 37 | +* Topic |
| 38 | + |
| 39 | +## Pagination |
| 40 | +The API wrapper allows pagination and adjusting page sizes of data using the `page` number and `per_page` `number: |
| 41 | +```python |
| 42 | +from worldbank import api as wb |
| 43 | + |
| 44 | +instances = [] |
| 45 | +current_page = 1 |
| 46 | +total_pages = float('inf') |
| 47 | +total_instances = float('inf') |
| 48 | +per_page = 500 |
| 49 | +while current_page <= total_pages: |
| 50 | + summary, page_instances = Indicator.get(page=current_page, per_page=per_page) |
| 51 | + total_pages = summary['pages'] |
| 52 | + total_instances = summary['total'] |
| 53 | + current_page += 1 |
| 54 | + instances += page_instances |
| 55 | +``` |
0 commit comments