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 official 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 and also for a few special case locations. (Also it is possible to force the use of the internal static files.)

There is a fuzzy matching look up that can handle abbreviations in country names like Dem. for Democratic and Rep. for Republic.

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_country_name_from_ison(4)  # returns 'Afghanistan'
Country.get_country_name_from_m49(4)  # returns 'Afghanistan'

Country.get_iso3_country_code_fuzzy('Sierra')
# performs fuzzy match and returns ('SLE', False). The False indicates a fuzzy rather than exact match.
assert Country.get_iso3_country_code_fuzzy('Czech Rep.')
# returns ('CZE', False)

Country.get_country_info_from_iso2('jp')
# {'ISO-alpha2 Code': 'JP', 'ISO-numeric Code': '392', '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', 'Capital City': 'Tokyo'}

Country.get_countries_in_region('Channel Islands')
# ['GGY', 'JEY']
len(Country.get_countries_in_region('Africa'))
# 60
Country.get_countries_in_region(13)
# ['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

This version

1.3.9

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.3.9.tar.gz (199.9 kB view details)

Uploaded Source

Built Distribution

hdx_python_country-1.3.9-py2.py3-none-any.whl (98.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: hdx-python-country-1.3.9.tar.gz
  • Upload date:
  • Size: 199.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for hdx-python-country-1.3.9.tar.gz
Algorithm Hash digest
SHA256 b0ddbb7810b3c1b8d805bc3a04aa429c14c7ac84640af40ccf2d7655c0dac087
MD5 e9cbd27200d9416ff88e8cd59f9dd8a0
BLAKE2b-256 887a0c9aa0279e5563ab72b3e2ab7c29ed24d2cbbeba125dd6e4cf8971beb8a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hdx_python_country-1.3.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 98.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for hdx_python_country-1.3.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c0012a388b54385eab19b3fbc4a5ddac37b34e0080d735bcf4419713caf47f88
MD5 9347dbd9dfab04b24de9afdacafb0190
BLAKE2b-256 fe3f66e5ef4e114aabb6744cb8c2ee9488dd19b45943367f0f9664ea057a0623

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