isocodes

raw JSON →
2025.8.25 verified Mon Apr 27 auth: no python

isocodes provides lists of various ISO standards (e.g., country, language, language scripts, and currency names) in one place. Current version 2025.8.25, updated regularly with new releases.

pip install isocodes
error ModuleNotFoundError: No module named 'isocodes'
cause isocodes not installed or misspelled (common: 'iso-codes' vs 'isocodes').
fix
Install via pip: pip install isocodes (no hyphen).
error AttributeError: 'IsoCodes' object has no attribute 'countries'
cause The attribute name might vary; some versions have 'countries' as a property, others as a list.
fix
Check available attributes with dir(codes); likely the correct attribute is 'countries' (plural).
error TypeError: 'NoneType' object is not iterable
cause Missing data files or incorrect initialization; IsoCodes expects data to be installed alongside the package.
fix
Reinstall the package to ensure data files are present: pip install --upgrade --force-reinstall isocodes.
gotcha Data fields (e.g., 'name', 'alpha_2') are stored as lists of objects, not dictionaries. Access via attribute (e.g., country.name) not via 'get'.
fix Use dot notation: e.g., country.name, not country.get('name').
deprecated Direct import of JSON data paths is deprecated. Use IsoCodes class to access data programmatically.
fix Use the IsoCodes class instead of accessing data files via pkg_resources or importlib_resources directly.
gotcha The 'countries' attribute returns all countries including those that are not ISO 3166-1? Actually it's the full list; ensure you filter by 'alpha_2' if needed.
fix Filter as needed: e.g., [c for c in codes.countries if c.alpha_2 == 'US'].

Create an IsoCodes instance and iterate over countries to access attributes like name, alpha_2, and numeric.

from isocodes import IsoCodes

codes = IsoCodes()
for country in codes.countries:
    if country.name == 'United States':
        print('Alpha-2:', country.alpha_2, ', Numeric:', country.numeric)