Skip to main content

HDX Python country mapping utilities

Project description

Travis-CI Build Status Coveralls Build Status

The HDX Python Country Library provides country mappings including ISO 2 and ISO 3 letter codes (ISO 3166) and regions using live data from the UNStats M49 website and World Bank api with fallbacks to internal static files if there is any problem with retrieving data from the urls. (Also it is possible to force the use of the internal static files.)

This library is part of the Humanitarian Data Exchange (HDX) project. If you have humanitarian related data, please upload your datasets to HDX.

Usage

The library has detailed API documentation which can be found here: http://ocha-dap.github.io/hdx-python-country/. The code for the library is here: https://github.com/ocha-dap/hdx-python-country.

Countries

The usage of the country mappings functionality is best illustrated by some examples:

from hdx.location.country import Country

Country.get_country_name_from_iso3('jpn', use_live=False)  # returns 'Japan'
# uselive=False forces the use of internal files instead of accessing the live feeds.
# It only needs to be supplied to the first call as the data once loaded is held
# in internal dictionaries for future use.
Country.get_country_name_from_iso2('Pl')  # returns 'Poland'
Country.get_iso3_country_code('UZBEKISTAN')  # returns 'UZB'

Country.get_iso3_country_code_partial('Sierra')
# performs partial match and returns ('SLE', False)

Country.get_country_info_from_iso2('jp')
# {'Sub-region Name': 'Eastern Asia', 'M49 Code': '392', 'ISO-alpha3 Code': 'JPN',
'Developed / Developing Countries': 'Developed', 'Land Locked Developing Countries (LLDC)': '',
'Global Name': 'World', 'Region Name': 'Asia', 'Least Developed Countries (LDC)': '',
'Intermediate Region Code': '', 'Region Code': '142', 'Country or Area': 'Japan', 'Sub-region Code': '030',
'Intermediate Region Name': '', 'Small Island Developing States (SIDS)': '', 'Global Code': '001'}

Country.get_countries_in_region('Channel Islands')
# ['GGY', 'JEY']
len(Country.get_countries_in_region('Africa'))
# 60
Country.get_countries_in_region('013')
# ['BLZ', 'CRI', 'GTM', 'HND', 'MEX', 'NIC', 'PAN', 'SLV']

get_countries_in_region accepts regions, intermediate regions or subregions as specified on the UNStats M49 website.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hdx-python-country-1.0.2.tar.gz (184.4 kB view details)

Uploaded Source

Built Distribution

hdx_python_country-1.0.2-py2.py3-none-any.whl (79.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file hdx-python-country-1.0.2.tar.gz.

File metadata

File hashes

Hashes for hdx-python-country-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2d20647e3ca71e7bd5002c703d1a751654a88b3c6c64f96faa7f8b1f1088ee83
MD5 a2cd6e2518b0feacacc088311d5f4751
BLAKE2b-256 f5406fb16d4ce3fcdc8d6a162087c77519928b4de487746b664caa4224a4a351

See more details on using hashes here.

File details

Details for the file hdx_python_country-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for hdx_python_country-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c3acfd0350ea5355f896d8c07ce463749cc2c63f0316caa7e368d7c803fafc25
MD5 fc6e1b3dfdcc646a2c8892388336571c
BLAKE2b-256 39d79e0c4b9fb5d1964d2b09be99e940351568c91bb2109a4ee7cc2b2306d380

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page