Country Converter (coco)

1.3.2 · active · verified Sat Apr 11

The country converter (coco) is a Python package designed to convert and match country names between various classification schemes and different naming conventions. It leverages regular expressions for robust matching and supports a wide array of classifications, including ISO, UN, EU, OECD, FIFA, IOC, continents, and several MRIO/IAM databases. The current version is 1.3.2, and it typically sees several updates per year to enhance classifications and features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `country_converter` library and use its `convert` function to transform country names between different classification schemes like ISO2, ISO3, and various continent classifications.

import country_converter as coco

# Convert a single country name to its ISO3 code
iso3_code = coco.convert(names='Germany', to='ISO3')
print(f"The ISO3 code for Germany is: {iso3_code}")

# Convert a list of country names to ISO2 codes
country_names = ['France', 'Italy', 'Spain']
iso2_codes = coco.convert(names=country_names, to='ISO2')
print(f"The ISO2 codes for {country_names} are: {iso2_codes}")

# Convert a country name to its continent (7-continent classification)
continent = coco.convert(names='Brazil', to='Continent7')
print(f"Brazil is in: {continent}")

view raw JSON →