Skip to content

Commit 9344cd4

Browse files
committed
removes the obsolete Catalog API and improves README
1 parent fb6c0b6 commit 9344cd4

File tree

4 files changed

+50
-236
lines changed

4 files changed

+50
-236
lines changed

README.md

Lines changed: 48 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -2,167 +2,54 @@
22
A Python 2/3 wrapper for the World Bank API
33
See World Bank [Developer Information](https://datahelpdesk.worldbank.org/knowledgebase/topics/125589-developer-information) to get information on the raw API
44

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
895

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+
```
9324

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
16726

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+
```

README.rst

Whitespace-only changes.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Versions should comply with PEP440. For a discussion on single-sourcing
1818
# the version across setup.py and the project code, see
1919
# https://packaging.python.org/en/latest/single_source_version.html
20-
version='0.2',
20+
version='1.1',
2121

2222
description='A Python 2/3 API wrapper for World Bank',
2323
long_description=long_description,

worldbank/api.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -675,78 +675,6 @@ def get(cls, **kwargs):
675675
return summary, instances
676676

677677

678-
class Catalog(object):
679-
"""
680-
A Dataset in the World Bank Open Data Datalog
681-
682-
Attributes:
683-
id (str):
684-
metatypes (list):
685-
686-
See https://datahelpdesk.worldbank.org/knowledgebase/articles/902049-data-catalog-api
687-
"""
688-
689-
def __init__(self, id, metatypes):
690-
self.id = id
691-
self.metatypes = metatypes
692-
693-
def __str__(self):
694-
return self.id
695-
696-
def __repr__(self):
697-
return '<%s %s id=%s>' % (self.__class__.__name__, id(self), self.id)
698-
699-
@classmethod
700-
def from_api(cls, data):
701-
"""
702-
Returns a class instance from API data
703-
"""
704-
catalog_id = data['id']
705-
metatypes = data['metatype']
706-
return cls(catalog_id, metatypes)
707-
708-
@classmethod
709-
def get(cls, catalog=None, field=[], **kwargs):
710-
"""
711-
Arguments:
712-
catalog (str, optional): id of the desired Catalog
713-
field (list|tuple|set): desired fields
714-
Keyword Arguments:
715-
page (int, optional): The page number to get, defaults to 1.
716-
per_page (int, optional): The number of items to fetch in each page, defaults to 50.
717-
718-
Returns
719-
list: instances matching the query
720-
"""
721-
field = ';'.join(field)
722-
url = '%s/datacatalog/' % domain
723-
if catalog:
724-
url = '%s/%s' % (url, catalog.id)
725-
if field:
726-
url = '%s/metatypes/%s' % (url, field)
727-
data = _request(url, parameters=kwargs)
728-
instances = [cls.from_api(item) for item in data['datacatalog']]
729-
return instances
730-
731-
@classmethod
732-
def search(cls, query, **kwargs):
733-
"""
734-
Arguments:
735-
query (str): search query
736-
737-
Keyword Arguments:
738-
page (int, optional): The page number to get, defaults to 1.
739-
per_page (int, optional): The number of items to fetch in each page, defaults to 50.
740-
741-
Returns
742-
list: instances matching the query
743-
"""
744-
url = '%s/v2/datacatalog/search/%s' % (domain, query)
745-
data = _request(url, parameters=kwargs)
746-
instances = [cls.from_api(item) for item in data['datacatalog']]
747-
return instances
748-
749-
750678
if __name__ == '__main__':
751679
summary, indicators = Indicator.get()
752680
summary, country_indicators = CountryIndicator.get(indicators[0])
@@ -760,5 +688,4 @@ def search(cls, query, **kwargs):
760688
summary, country = Country.by_lending_type(lending_types[0])
761689
summary, indicators = Indicator.by_source(sources[0])
762690
summary, indicators = Indicator.by_topic(topics[0])
763-
summary, countryindicators = CountryIndicator.get(indicators[0])
764-
catalog = Catalog.get()
691+
summary, countryindicators = CountryIndicator.get(indicators[0])

0 commit comments

Comments
 (0)