Install & Compatibility
Where this runs
tested against v0.7.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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 55.5MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.9s · import 0.000s · 56MB
53MB installed
● package 53MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pycountry_convert
✓ import pycountry_convert as pc
This example demonstrates how to convert a country name to its ISO Alpha-2 code, then to its continent code, and finally to the continent name, chaining the necessary functions. Direct conversion from country name to continent name is not available, requiring these intermediate steps.
import pycountry_convert as pc
# Convert country name to Alpha-2 code
country_name = 'Germany'
try:
country_alpha2 = pc.country_name_to_country_alpha2(country_name, cn_name_format='default')
print(f"Alpha-2 code for {country_name}: {country_alpha2}")
# Convert Alpha-2 code to continent code
continent_code = pc.country_alpha2_to_continent_code(country_alpha2)
print(f"Continent code for {country_alpha2}: {continent_code}")
# Convert continent code to continent name
continent_name = pc.convert_continent_code_to_continent_name(continent_code)
print(f"Continent name for {continent_code}: {continent_name}")
except KeyError:
print(f"Could not find data for country: {country_name}")
Debug
Known issues
gotchaDirect conversion from country name to continent name is not supported. Users must first convert the country name to an ISO Alpha-2 code, then convert the Alpha-2 code to a continent code, and finally convert the continent code to its name.fixChain the conversion functions: `country_name_to_country_alpha2()` -> `country_alpha2_to_continent_code()` -> `convert_continent_code_to_continent_name()`.
affects: All versions (0.x.x)
gotchaThe `pycountry-convert` library has not been updated since version 0.7.2 in February 2018. This means its internal data for countries and continents may be outdated and might not reflect recent geopolitical changes or updates to ISO standards, even if its dependency `pycountry` (which has seen more recent updates) is installed separately.fixBe aware of potential data staleness. For highly current data, consider verifying results against other sources or implementing manual updates if specific country/continent mappings are critical.
affects: 0.7.2 and potentially earlier
gotchaFor large datasets, repeatedly calling conversion functions can be slow due to re-computation. The library itself does not inherently cache results between calls.fixFor performance-critical applications, consider implementing caching (e.g., using `functools.lru_cache` on a wrapper function) or pre-processing and mapping unique country names/codes once.
affects: All versions (0.x.x)
Upgrade
Version history
0.7.2latest on PyPI · released Feb 18, 2018
Audit
Dependencies
pycountryrequiredCore dependency for accessing ISO country, subdivision, language, currency, and script definitions.
pprintppoptionalUsed for pretty printing, likely for debugging or enhanced output.
Resources
No resource links recorded.