Skip to content

Software & API that maintains the latest changes/updates to the ISO 3166-1 & 2 country codes and naming conventions, as per the ISO 3166 newsletter and online catalogue 🌎.

License

Notifications You must be signed in to change notification settings

amckenna41/iso3166-updates

Repository files navigation

iso3166-updates 🌎

iso3166_updates pytest

PythonV Platforms Documentation Status License: MIT Issues

globe

Software and accompanying RESTful API that checks for any updates/changes to the ISO 3166-1 and ISO 3166-2 country codes and subdivision naming conventions, as per the ISO 3166 newsletter (https://www.iso.org/iso-3166-country-codes.html) and Online Browsing Platform (OBP) (https://www.iso.org/obp/ui). Available via a lightweight Python software package & REST API.

Quick Start πŸƒ

  • A demo of the software and API is available here.
  • The front-end API is available here.
  • The documentation for the software & API is available here.
  • A Medium article that dives deeper into iso3166-updates is available here.
  • A demo of the script used to pull and export all the latest updates is available here.

Table of Contents

Introduction

iso3166-updates is a software and accompanying API that consists of a series of scripts that check for any updates/changes to the ISO 3166 country codes and subdivision naming conventions, as per the ISO 3166 newsletter (https://www.iso.org/iso-3166-country-codes.html) and Online Browsing Platform (OBP) (https://www.iso.org/obp/ui).

The ISO 3166 standard by the ISO (International Organization for Standardisation) defines codes for the names of countries, dependent territories, special areas of geographical interest, consolidated into the ISO 3166-1 standard [1], and their principal subdivisions (e.g., provinces, states, departments, regions etc), which comprise the ISO 3166-2 standard [2]. Additionally, the ISO 3166-3 part of the standard represents codes formerly used for countries/territories etc which have been removed from the ISO 3166-1. The ISO 3166-1 was first published in 1974 and currently comprises 249 countries, 193 of which are sovereign states that are members of the United Nations πŸ‡ΊπŸ‡³ [1]. The ISO 3166-2 was first published in 1998 and as of November 2023 there are 5,039 codes defined in it [2]. The ISO 3166-3 was first published in 1974 and as of April 2024 there are 73 codes defined in it [[1]]. In the software, only the ISO 3166-1 and ISO 3166-2 are used.

Problem Statement:

The ISO is a very dynamic organisation and regularly change, update, and/or remove entries within its library of standards, including the ISO 3166. Additions, changes and or deletions to country/territorial codes occur less often in the ISO 3166-1, but changes are more frequent for the ISO 3166-2 codes due to there being thousands more entries, thus it can be difficult to keep up with and track these changes. These changes can occur for a variety of geopolitical and administrative reasons. Previously these changes were communicated via newsletters; but as of July 2013 these changes are now communicated via their online catalogue/Online Browsing Platform (OBP), or via a database, which usually costs money to subscribe to (up to $300) [3]. Usually these updates are conveyed at the end of the year, with amendments and updates occasionally published at various times throughout the year [4].

This software and accompanying API make it extremely easy to check for any new or historic updates to a country or set of country's ISO 3166-2 codes for free; with an easy-to-use interface and Python package and API, ensuring that you get the most up-to-date and accurate ISO 3166-2 codes and naming conventions.

Intended Audience:

This software and accompanying API is for anyone working with country data at the ISO 3166 level. It's of high importance that the data you are working with is correct and up-to-date, especially with consistent changes being posted every year since 1996 (excluding 1997, 1998, 1999, 2001 and 2006). Also, it's aimed not just at developers of ISO 3166 applications but for anyone working in that space, hence the creation of an easy-to-use API (https://iso3166-updates.vercel.app/).

Last Updated

The list of ISO 3166 updates was last updated on August 2025, with 911 individual published updates. A log of the latest ISO 3166 updates can be seen in the UPDATES.md.

Requirements

Installation

Install the latest version of iso3166-updates via PyPi using pip:

pip3 install iso3166-updates

Documentation

Documentation for the software and accompanying API is available on the software's readthedocs page. Additionally the API's documentation is available on the API homepage. A demo of both is also available here.

API

The main API endpoint and homepage is:

https://iso3166-updates.vercel.app/

The other endpoints available in the API are /api/all, /api/alpha/<input_alpha>, /api/year/<input_year>, /api/country_name/<input_country_name>, /api/search/<input_search> and /api/date_range/<input_date_range>.

  • /api: main homepage and API documentation.

  • /api/all: get all of the ISO 3166 updates/changes data for all countries and publication years.

  • /api/alpha: get all the ISO 3166 updates/changes data for one or more countries according to their ISO 3166-1 alpha-2, alpha-3 or numeric country codes. A single alpha code or a list of them can be passed to the API e.g. /api/alpha/AL, /api/alpha/BWA, /api/alpha/FR,DE,HUN,IDN,504. If an invalid alpha code is input then an error will be returned. This endpoint can be used in conjunction with the year and date_range endpoints to get the country updates for a specific country and year, and the country updates over a specific date range, respectively. This will be in the format: /api/alpha/<input_alpha>/year/<input_year> and /api/alpha/<input_alpha>/date_range/<input_date_range>, respectively.

  • /api/year: get all the ISO 3166 updates/changes data for one or more countries according to a specific year, year range, a cut-off year to get updates less than/more than a year or all updates except for a year, e.g. /api/year/2017, /api/year/2010-2015, /api/year/<2009, /api/year/>2002 and /api/year/<>2020. If an invalid year is input then an error will be returned. This endpoint can be used in conjunction with the alpha endpoint to get the country updates for a specific country and year. This will be in in the format /api/alpha/<input_alpha>/year/<input_year>.

  • /api/country_name: get all the ISO 3166 updates/changes data for one or more countries according to their name, as it is commonly known in English, e.g. /api/country_name/Tajikistan, /api/country_name/Benin,Togo, /api/country_name/Russia,Sudan,Swaziland. If an invalid country name is input then an error will be returned. This endpoint can be used in conjunction with the year endpoint to get the country updates for a specific country and year. This will be in in the format /api/country_name/<input_country_name>/year/<input_year>.

  • /api/search: get all the ISO 3166 updates/changes data for one or more countries that match the inputted search terms. A single keyword/term or list of them can be passed to the API e.g. /api/search/Brazil, /api/search/Addition,deletion, /api/search/2017-11-23. A closeness function is used to search through the updates objects, finding any applicable matches to the keywords input via the Change and Description of Change attributes. If a date is explicitly input then the Date Issued attributes will also be searched. If no matching objects found then an error will be returned.

  • /api/date_range: get all the ISO 3166 updates/changes data for one or more countries that were published within a specified input date range e.g. /api/date_range/2011-12-09,2014-01-10, /api/date_range/2013-08-02,2015-07-10, /api/date_range/2018-05-12. If a single date is input it will act as the starting date within the date range, with the end of the range being the current day. If an invalid date type/format value is input then an error will be returned. This endpoint can be used in conjunction with the alpha endpoint to get the country updates for a specific country and date range. This will be in in the format /api/alpha/<input_alpha>/date_range/<input_date_range>.

Attributes

There are three main query string parameters that can be passed through several of the endpoints of the API:

  • Change: overall summary of change/update made.
  • Description of Change: more in-depth info about the change/update that was made, including any remarks listed on the official ISO page.
  • Date Issue: date that the change was communicated.
  • Source: name and or edition of newsletter that the ISO 3166 change/update was communicated in (pre 2013), or the link to the country's ISO Online Browsing Platform page.

Query String Parameters

There are three main query string parameters that can be passed through several of the endpoints of the API:

  • sortBy: sort the output results by publication date (Date Issued), either descending or ascending. By default, the updates data will be returned alphabetically, according to ISO 3166 2 letter country code, but you can order by date. The parameter accepts two values: dateDesc and dateAsc - sorting the output by date descending or ascending, respectively. If an invalid value input then the output is sorted by country code. This can be appended to all of the endpoints, e.g /api/all?sortBy=dateDesc, /api/year/2010-2015?sortBy=dateAsc, /api/date_range/2019-01-01?sortBy="" (sorted by country code).
  • likeness: this is a value between 1 and 100 that increases or reduces the % of similarity/likeness that the inputted search terms have to match to the updates data in the Change and Desc of Change attributes. This can only be used in the /api/search endpoint. Having a higher value should return more exact and less matches and having a lower value will return less exact but more matches, e.g /api/search/Paris?likeness=50, /api/search/canton?likeness=90 (default=100).
  • excludeMatchScore: exclude the matchScore` attribute from the search results when using the /api/search endpoint. The match score is the % of a match each returned updates data object is to the search terms, with 100% being an exact match. By default the match score is returned for each object, e.g /api/search/addition?excludeMatchScore=1, ``/api/search/New York?excludeMatchScore=1`` (default=0).

Staying up to date

The list of ISO 3166 updates was last updated on May 2025.

The object storing all updates - iso3166-updates.json - for the software package is consistently checked for the latest updates using a Google Cloud Run microservice (iso3166-check-for-updates). The application is built using a custom Docker container that uses the iso3166-updates Python software to pull all the latest updates/changes from the various data sources, to check for the latest updates within a certain period e.g. the past 6-12 months (this month range is used as the ISO usually publishes their updates at the end of the year with occasional mid-year updates). The app compares the generated output with that of the updates JSON currently in the software package and will replace this json to integrate the latest updates found, such that the API will have the most up-to-date and accurate data. A Cloud Scheduler is used to call the application on the aforementioned schedule.

Additionally, a GitHub Issue in the custom-built iso3166-updates, iso3166-2 and iso3166-flag-icons repositories will be automatically created that formats and tabulates all updates/changes that need to be implemented into the JSONs on the aforementioned repos.

Ultimately, this Cloud Run microservice ensures that the software and associated APIs are up-to-date with the latest, accurate and reliable ISO 3166-2 information for all countries/territories/subdivisions etc.

Usage

Below are some examples of using the custom-built iso3166-updates Python package.

Import package:

from iso3166_updates import *

Create instance of Updates() class:

iso = Updates()

Create instance of Updates() class with custom updates filepath:

iso = Updates(custom_updates_filepath="custom_updates_path.json")

Get all listed changes/updates for all countries and years:

iso.all

Get all listed ISO 3166 changes/updates for Andorra (AD):

iso["AD"]
#iso["AND"]
#iso["020"]

Get all listed ISO 3166 changes/updates for BA, DE, FRA, HUN, PY (600):

iso["BA","DE","FRA","HUN","600"]

Get all listed ISO 3166 changes/updates for all countries, for years 2002, 2005 and 2009:

iso.year("2002, 2005, 2009")

Get all listed ISO 3166 changes/updates for all countries, for year range 2013-2016, inclusive:

iso.year("2013-2016")

Get all listed ISO 3166 changes/updates for all countries, for all years after 2017, inclusive:

iso.year(">2017")

Get all listed ISO 3166 changes/updates for all countries, for all years before 2010:

iso.year("<2010")

Get all listed ISO 3166 changes/updates for all countries, excluding years 2010 & 2019:

iso.year("<>2010,2019")

Get all listed ISO 3166 changes/updates published that have London or Edinburgh in them via searching:

iso.search("London, Edinburgh")

Get all listed ISO 3166 changes/updates published that have Addition or Deletion in them via searching, using a likeness score of 0.8:

iso.search("addition, deletion", likeness_score=0.8)

Get any listed ISO 3166 changes/updates published within the date range 2012-03-12 to 2015-06-25, inclusive:

iso.date_range("2012-03-12,2015-06-25")

Get any listed ISO 3166 changes/updates published from the date range 2021-10-02, inclusive, sort by date descending rather than country code:

iso.date_range("2021-10-02", sort_by_date="dateDesc")

Add custom ISO 3166 change/update to main iso3166-updates.json object:

iso.custom_update("LI", change="Brand new LI subdivision", date_issued="2025-01-01", description_of_change="Short description here.")
iso.custom_update("IE", change="Brand new Belfast subdivision", date_issued="2020-05-12", description_of_change="", source="https:...")

Delete custom ISO 3166 change/update to main iso3166-updates.json object:

iso.custom_update("LI", change="Brand new LI subdivision", date_issued="2025-01-01", delete=1)
iso.custom_update("IE", change="Brand new Belfast subdivision", date_issued="2020-05-12", delete=1)

Get total number of individual ISO 3166 country updates:

len(iso)

Get size of dataset in MB:

iso.__sizeof__()

Check for the latest updates data from the repository:

iso.check_for_updates()  #compares local dataset with the latest version in the repository

Directories

  • /iso3166_updates - source code for iso3166-updates Python package.
  • /iso3166-check-for-updates - all code and files related to the serverless Google Cloud Run microservice for the check-for-updates function which is a periodically called Cloud Run app that uses the Python software to check for the latest updates for all ISO 3166 countries, ensuring the API and jsons are reliable, accurate and up-to-date.
  • /docs - documentation for iso3166-updates, available on readthedocs.
  • /tests - unit and integration tests for iso3166-updates software and API.
  • /iso3166_updates_export - directory of scripts that pull and export all the latest ISO 3166 data from the various data sources.
  • UPDATES.md - log of all the latest updates from 2022 onwards.

Issues

Any issues, errors/bugs or enhancements can be raised via the Issues tab in the repository.

Contact

If you have any questions or comments, please contact amckenna41@qub.ac.uk or raise an issue on the Issues tab.

Other ISO 3166 repositories

Below are some of my other custom-built repositories that relate to the ISO 3166 standard.

  • iso3166-updates-api: frontend API for iso3166-updates.
  • iso3166-2: a lightweight bespoke custom-built Python package and dataset, and accompanying API, that can be used to access all of the world's ISO 3166-2 subdivision data. A plethora of data attributes are available per country and subdivision including: name, local name, code, parent code, type, lat/longitude and flag. Currently, the package and API supports data from 250 countries/territories, according to the ISO 3166-1 standard and >5000 subdivisions, according to the ISO 3166-2 standard.
  • iso3166-2-api: frontend API for iso3166-2.
  • iso3166-flag-icons: a comprehensive library of over 3500 country and regional flags from the ISO 3166-1 and ISO 3166-2 standards.

References

[1]: ISO 3166-1: https://en.wikipedia.org/wiki/ISO_3166-1
[2]: ISO 3166-2: https://en.wikipedia.org/wiki/ISO_3166-2
[3]: ISO Country Codes Collection: https://www.iso.org/publication/PUB500001
[4]: ISO Country Codes: https://www.iso.org/iso-3166-country-codes.html
[5]: ISO 3166-1 flag-icons repo: https://github.com/lipis/flag-icons
[6]: ISO 3166-2 flag-icons repo: https://github.com/amckenna41/iso3166-flag-icons

Support

Star it on GitHub

Buy Me A Coffee

Back to top

About

Software & API that maintains the latest changes/updates to the ISO 3166-1 & 2 country codes and naming conventions, as per the ISO 3166 newsletter and online catalogue 🌎.

Resources

License

Stars

Watchers

Forks

Packages

No packages published