Registry / data / country-converter

country-converter

JSON →
library1.3.2pypypi✓ verified 26d ago

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.

pip install country-converter
INSTALL
IMPORT
SIG · COUNTRY-CONVERTER
C
country-converter
datapythonv1.3.2
Install
7.9s avg
Import
957ms
Disk
165MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.968s · 164.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.9s · import 0.946s · 157MB
165MB installed
● package 165MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CountryConverter
import country_converter as coco

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}")
coco --version
Debug
Known issues
breakingPrior to version 1.0.0, and specifically in v0.7.6, the library made a breaking change requiring additional custom data to explicitly specify the 'ISO2' classification for regex matching. Updates from pre-1.0 versions may require code adjustments if custom data was used.
fix
Ensure any custom country data provided to `country-converter` includes an 'ISO2' column with appropriate values for matching, especially if upgrading from versions prior to 0.7.6.
affects: <1.0.0
gotchaBy default, `country-converter` logs a warning to the Python logging logger if no match is found for a given country name during conversion. This can lead to silently missed conversions if log outputs are not monitored.
fix
Monitor the Python logging output for `country_converter` warnings, or explicitly handle `None` (or the original unmatched input) in the results. For finer control, you can configure the logging behavior or specify `not_found='keep'` or `not_found='raise'` in the `convert` method to either retain the original input or raise an error.
affects: All versions
gotchaWhen converting country names, if the input format is ambiguous (e.g., 'US' could be 'ISO2' or a short name), the library attempts to automatically determine the source format. This auto-detection might occasionally lead to incorrect conversions for ambiguous inputs.
fix
For ambiguous country names or when certainty is required, explicitly specify the source classification using the `src` parameter in the `convert` method (e.g., `coco.convert(names='US', src='ISO2', to='ISO3')`).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'country_converter'
The `country-converter` package has not been installed or the Python environment where the script is being run does not have it installed.
fix
Install the package using pip: `pip install country-converter`
AttributeError: 'CountryConverter' object has no attribute 'convert'
This typically happens if you try to call `convert` directly on the `country_converter` module instead of an instantiated `CountryConverter` object, or if there's a typo in the method name. The `convert` method is part of the `CountryConverter` class.
fix
First, instantiate the `CountryConverter` class, then call the `convert` method on that instance:
```python
import country_converter as coco
cc = coco.CountryConverter()
countries = ['Germany', 'France']
converted_countries = cc.convert(names=countries, to='ISO3')
```
ValueError: Cannot resolve country name for...
The input country name or code is not recognized by the `country-converter` library, possibly due to a typo, an unofficial name, or an unsupported classification scheme for the `src` parameter. The library will often log a warning when no match is found.
fix
Verify the spelling and format of the input country names/codes. Ensure they are standard names or codes recognized by common classification schemes (e.g., ISO2, ISO3, UN numeric). If the input format is known, specify the `src` parameter (e.g., `src='name_short'`). You can also set `not_found=None` to return `None` for unmatchable entries instead of raising an error or keeping the original name.
Input contains multiple country names in a single string (e.g., 'United States, Canada')
The `country-converter` library's `convert` method expects each element in the `names` input to represent a single country name or code. When a single string contains multiple comma-separated country names, it treats the entire string as one potentially unmatchable entry.
fix
Split the string containing multiple country names into a list of individual country names before passing it to `country_converter`. For example:
```python
import country_converter as coco
cc = coco.CountryConverter()
country_string = 'United States, Canada, Mexico'
country_list = [c.strip() for c in country_string.split(',')]
converted_names = cc.convert(names=country_list, to='ISO3')
```
Upgrade
Version history
1.3.2latest on PyPI · released Oct 22, 2025
Audit
Dependencies
pandasrequiredUsed internally for data storage and efficient Series conversion.
pycountryrequiredProvides access to official ISO databases for country information.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
country-converter — pip install country-converter · libregistry