{"id":2077,"library":"iso3166","title":"ISO 3166-1 Country Definitions","description":"`iso3166` is a lightweight Python library providing self-contained definitions for ISO 3166-1 country codes. It allows conversion between two-letter (alpha-2), three-letter (alpha-3), three-digit (numeric) codes, and country names. The current version is 2.1.1, released in July 2022, and updates are typically made to incorporate changes in the ISO 3166-1 standard.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"http://github.com/deactivated/python-iso3166","tags":["iso","country codes","i18n","standardization"],"install":[{"cmd":"pip install iso3166","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The 'countries' lookup object is directly exposed for convenience. While 'import iso3166' works, accessing 'iso3166.countries' is less common than direct import.","wrong":"import iso3166; countries = iso3166.countries","symbol":"countries","correct":"from iso3166 import countries"}],"quickstart":{"code":"from iso3166 import countries\n\n# Get a country by its alpha-2 code\nus = countries.get('US')\nprint(f\"Alpha-2: {us.alpha2}, Name: {us.name}, Alpha-3: {us.alpha3}, Numeric: {us.numeric}\")\n\n# Get a country by its alpha-3 code\njapan = countries.get('JPN')\nprint(f\"Alpha-2: {japan.alpha2}, Name: {japan.name}\")\n\n# Iterate through all countries\nfor country in countries:\n    if country.numeric == '036': # Australia\n        print(f\"Found country by numeric code: {country.name}\")\n        break","lang":"python","description":"This quickstart demonstrates how to import the `countries` object and retrieve country data using various ISO 3166-1 codes (alpha-2, alpha-3, numeric) or iterate through the entire list. Each country object provides `name`, `alpha2`, `alpha3`, and `numeric` attributes."},"warnings":[{"fix":"If you need subdivision data, install `iso3166-2` (`pip install iso3166-2`). If you only need top-level country codes, `iso3166` is correct.","message":"This library (`iso3166`) *only* provides ISO 3166-1 country codes (e.g., 'US', 'USA'). It does not include ISO 3166-2 country subdivisions (e.g., states, provinces, regions). For subdivision data, consider libraries like `iso3166-2` which is a separate package.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Try updating the package (`pip install --upgrade iso3166`), uninstalling and reinstalling it, or restarting your Python kernel/environment. Manual deletion of residual package files might also be necessary in some cases.","message":"Users sometimes encounter `ImportError: cannot import name 'countries' from 'iso3166'`. This can be due to environment issues, incorrect package installation, or cached interpreter states (e.g., in Jupyter notebooks).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that major new features or significant code changes are less likely from the original maintainer. The library remains suitable for its core purpose of ISO 3166-1 data lookup.","message":"The official GitHub repository (`deactivated/python-iso3166`) is marked as 'deactivated'. While the PyPI package still receives updates (primarily for ISO data changes) and is functional, the repository status might suggest less active new feature development or community interaction compared to other actively maintained projects.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}