ISO 3166-1 Country Definitions

2.1.1 · active · verified Thu Apr 09

`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.

Warnings

Install

Imports

Quickstart

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.

from iso3166 import countries

# Get a country by its alpha-2 code
us = countries.get('US')
print(f"Alpha-2: {us.alpha2}, Name: {us.name}, Alpha-3: {us.alpha3}, Numeric: {us.numeric}")

# Get a country by its alpha-3 code
japan = countries.get('JPN')
print(f"Alpha-2: {japan.alpha2}, Name: {japan.name}")

# Iterate through all countries
for country in countries:
    if country.numeric == '036': # Australia
        print(f"Found country by numeric code: {country.name}")
        break

view raw JSON →