pycountry-convert

Introduction

Extension of Python package pycountry providing conversion functions.

Badges

docs Documentation Status License Status
info Hits Contributors
tests Travis-CI Build Status Code Coverage Status
package PyPI Package latest release Supported versions
other Requirements Status

Install

pip install pycountry-convert

Architecture

Using country data derived from wikipedia, this package provides conversion functions between ISO country names, country-codes, and continent names.

Functions

  • map_countries(cn_name_format="default", cn_extras={}): Return a dict of countries with key as country name (standard and official) with ISO 3166-1 values Alpha 2, Alpha 3, and Numeric. This mapping will include countries defined within pycountry, Wikipedia, and whatever extra countries provided by parameter cn_extras. Parameter cn_name_format will format the country name as request to either be using the default layout “default”, lowercase “lower”, or uppercase “upper”.
  • country_alpha2_to_continent_code(): Convert country code ISO 3166-1 alpha-2 to continent name.
  • country_alpha2_to_country_name(cn_name_format="default"): Convert country code ISO 3166-1 alpha-2 to country name.
  • country_name_to_country_alpha2(cn_name, cn_name_format="default"): Convert country name to country code ISO 3166-1 alpha-2 .
  • country_alpha3_to_country_name(cn_name_format="default"): Convert country code ISO 3166-1 alpha-3 to country name.
  • country_name_to_country_alpha3(cn_name, cn_name_format="default"): Convert country name to country code ISO 3166-1 alpha-3 .
  • country_alpha3_to_country_alpha2(): Convert country code ISO 3166-1 alpha-3 to country code ISO 3166-1 alpha-2 .

Parameter: cn_name_format

  • COUNTRY_NAME_FORMAT_DEFAULT "default": Country names as provide by pycountry.
  • COUNTRY_NAME_FORMAT_LOWER "lower": All lowercase country names.
  • COUNTRY_NAME_FORMAT_UPPER "upper": All uppercase country names.

Parameter: cn_extras

Dictionary of { cn_name: cn_alpha2_code, … }

Dependencies

pycountry-convert module is built upon Python 3 and has dependencies upon several Python modules available within Python Package Index PyPI.