A Python package that pulls the latest updates & changes to all ISO3166 listed countries.
Project description
iso3166-updates
Automated scripts and API that check for any updates/changes to the ISO 3166-1 and ISO 3166-2 country codes and 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 Python software package and API; a demo of both is available here.
Table of Contents
- Introduction
- API
- Staying up to date
- Requirements
- Installation
- Usage
- Directories
- Issues
- Contact
- References
Introduction
iso3166-updates
is a repo that consists of a series of scripts that check for any updates/changes to the ISO 3166-2 country codes and subdivision naming conventions, as per the ISO 3166 newsletter (https://www.iso.org/iso-3166-country-codes.html). 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), which comprise the ISO 3166-2 standard [2].
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 29 November 2022 there are 5,043 codes defined in it [2].
Problem Statement:
The ISO is a very dynamic organisation and regularly change/update/remove entries within its library of standards, including the ISO 3166. Additions/changes/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 any changes to these codes. These changes can occur for a variety of geopolitical and bureaucratic reasons and are usually communicated via Newsletters on the ISO platform, their Online Browsing Platform (OBP) or via a database, which usually costs money to subscribe to [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 makes 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.
The earliest date for any ISO 3166 updates is 2000-06-21, and the most recent is 2022-11-29.
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 that you are working with is correct and up-to-date, especially with consistent changes being posted every year since 2000 (excluding 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.com).
API
An API is available that can be used to extract any applicable updates for a country via a URL. The API is available at the URL:
Three query string parameters/paths are available in the API - alpha2
, year
and months
. The 2 letter alpha-2 country code can be appeneded to the url as a query string parameter - "?alpha2=JP". A single alpha-2 or list of them can be passed to the API (e.g "FR", "DE", "HU, ID, MA"). The year parameter can be a specific year, year range, or a cut-off year to get updates less than/more than a year (e.g "?year=2017", "2010-2015", "<2009", ">2002"). Finally, the months parameter will gather all updates for 1 or more alpha-2 codes from a number of months from the present day (e.g "?month=6", "?month=48").
The API was hosted and built using GCP, with a Cloud Function being used in the backend which is fronted by an api gateway and load balancer. The function calls a GCP Storage bucket to access the back-end JSON with all ISO 3166 updates. A complete diagram of the architecture is shown below. Although, due to the cost of infrastructure the hosting was switched to Vercel (https://vercel.com/).
The API documentation and usage with all useful commands and examples to the API is available on the README of the iso3166-updates-api folder.
Staying up to date
The list of ISO 3166-2 updates was last updated on Nov 2022.
The object storing all updates, both locally (iso3166-updates.json) and on the API, are consistenly checked for the latest updates using a Google Cloud Function (iso3166-check-for-updates). The function uses the iso3166-updates
Python software to pull all the latest updates/changes from all ISO 3166-2 wiki's to check for the latest updates within a certain period e.g the past 3-6 months. The function compares the generated output with that of the updates json currently in the Google Cloud Storage bucket and will replace this json to integrate the latest updates found such that the API will have the most up-to-date data.
Additionally, a GitHub Issue in the iso3166-2
and iso3166-flag-icons
repositories will be automatically created that outlines all updates/changes that need to be implemented into the iso3166-2
and iso3166-flag-icons
JSONs and repos.
Ultimately, this Cloud Function ensures that the software and assoicated APIs are up-to-date with the latest ISO 3166-2 information for all countries/territories/subdivisions etc.
Requirements
- python >= 3.7
- pandas >= 1.4.3
- numpy >= 1.23.2
- requests >= 2.28.1
- beautifulsoup4 >= 4.11.1
- iso3166 >= 2.1.1
Installation
Install the latest version of iso3166-updates
via PyPi using pip:
pip3 install iso3166-updates --upgrade
Installation from source:
git clone -b master https://github.com/amckenna41/iso3166-updates.git
cd iso3166_updates
python3 setup.py install
Usage
Import package:
import iso3166_updates as iso3166_updates
Input parameters to get_updates function:
# -alpha2 ALPHA2, --alpha2 ALPHA2
# Alpha-2 code/s of ISO3166 countries to check for updates.
# -export_filename EXPORT_FILENAME, --export_filename EXPORT_FILENAME
# Filename for exported ISO3166 updates for CSV and JSON files.
# -export_folder EXPORT_FOLDER, --export_folder EXPORT_FOLDER
# Folder where to store exported ISO files.
# -export_json, --export_json
# Whether to export all found updates to json.
# -export_csv, --export_csv
# Whether to export all found updates to csv files in export folder.
# -year YEAR, --year YEAR
# Selected year to check for updates.
# -concat_updates, --concat_updates
# Whether to concatenate updates of individual countrys into the same json file or seperate.
Get all listed changes/updates for all countries which happens by default if no alpha-2 codes specified in input param, export csv and json to folder "iso3166-updates":
iso3166_updates.get_updates(export_folder="iso3166-updates", export_json=1, export_csv=1)
#exported files: /iso3166-updates/iso3166-updates.json and /iso3166-updates/iso3166-updates.csv
Get all listed changes/updates for Andorra from wiki (https://en.wikipedia.org/wiki/ISO_3166-2:AD), export csv and json to folder "iso3166-updates":
iso3166_updates.get_updates("AD", export_folder="iso3166-updates", export_json=1, export_csv=1)
#exported files: /iso3166-updates/iso3166-updates-AD.json and /iso3166-updates/iso3166-updates-AD.csv
Get all listed changes/updates for BA, DE, FR, HU, PY, export only JSON of updates to export folder "iso3166-updates":
iso3166_updates.get_updates(["BA","DE","FR","HU","PY"], export_folder="iso3166-updates", export_json=1, export_csv=0)
#exported files: /iso3166-updates/iso3166-updates-BA,DE,FR,HU,PY.json
Get any listed changes/updates for HU, IT, JA, KE from wiki, in the year 2018, export only to JSON with filename "iso3166-updates.json" and seperate updates into sepetate JSON files:
iso3166_updates.get_updates("HU, IT, JA, KE", year="2018", export_json=1, export_csv=0, export_filename="iso3166-updates", concat_updates=0)
#exported files: /iso3166-updates/iso3166-updates-HU,IT,JA,KE-2018.json
Get any listed changes/updates for Ireland from wiki (https://en.wikipedia.org/wiki/ISO_3166-2:IE), between years of 2012 and 2021, use default parameters:
iso3166_updates.get_updates("IE", year="2012-2021")
#exported files: /iso3166-updates/iso3166-updates-IE_2012-2021.json
Get any listed changes/updates for Tanzania from wiki (https://en.wikipedia.org/wiki/ISO_3166-2:TZ), with updates years >=2015, export only to CSV with filename iso3166-output":
iso3166_updates.get_updates("TA", year=">2015", export_filename="iso3166-output", export_json=0, export_csv=1)
#exported files: /iso3166-updates/iso3166-output-TA_>2015.csv
Get any listed changes/updates for Yemen from wiki (https://en.wikipedia.org/wiki/ISO_3166-2:YE), with updates years < 2010, use default parameters:
iso3166_updates.get_updates("YE", year="<2010")
#exported files: /iso3166-updates/iso3166-output-YE_<2010.json
Terminal/Command Line
Get all listed changes/updates for all countries, export csv and json to folder "iso3166-updates", print progress using verbose parameter:
python3 iso3166_updates.py --export_folder="iso3166-updates" --export_csv --export_json --verbose
Get all listed changes/updates for BY, DJ, ET, LY, PA for year range 2005-2010, export only CSV of updates to export folder "iso3166-updates", print progress using verbose parameter:
python3 iso3166_updates.py --alpha2="BY, DJ, ET, LY, PA" --year="2005-2010" --export_folder="iso3166-updates" --export_csv --no-export_json --verbose
The output to the above functions for the updates/changes to a ISO 3166-2 country returns 4 columns: Edition/Newsletter, Date Issued, Code/Subdivision change and Description of change in newsletter. For the CSV export, if more than one country input then an addition primary key column Country Code will be prepended to the first column, which will be the 2 letter ISO 3166-1 country code.
- Edition/Newsletter: Name and or edition of newsletter that ISO 3166-2 change/update was communicated in.
- Date Issued: Date that the change was communicated.
- Code/Subdivision change: Overall summary of change/update made.
- Description of change in newsletter: More in-depth info about the change/update that was made.
E.g. The output format of the exported CSV for AD (Andorra) is:
Edition/Newsletter | Date Issued | Code/Subdivision change | Description of change in newsletter |
---|---|---|---|
Newsletter I-8 | 2007-04-17 | Subdivisions added: 7 parishes... | Addition of the administrative subdivisions... |
Online Browsing Platform (OBP) | 2014-11-03 | No subdivision changes listed | Update List Source |
Online Browsing Platform (OBP) | 2015-11-27 | No subdivision changes listed | Update List Source |
E.g. The output format of the exported JSON for AD (Andorra) is:
{
AD: [
{
"Code/Subdivision change": "",
"Date Issued": "2015-11-27",
"Description of change in newsletter": "Update List Source",
"Edition/Newsletter": "Online Browsing Platform (OBP) (https://www.iso.org/obp/ui/#iso:code:3166:AD)"
},
{
"Code/Subdivision change": "",
"Date Issued": "2014-11-03",
"Description of change in newsletter": "Update List Source",
"Edition/Newsletter": "Online Browsing Platform (OBP) (https://www.iso.org/obp/ui/#iso:code:3166:AD)"
},
{
"Code/Subdivision change:" "Subdivisions added:7 parishes",
"Date Issued": "2007-04-17",
"Description of change in newsletter": "Addition of the administrative subdivisions and of their code elements",
"Edition/Newsletter": "Newsletter I-8 (https://web.archive.org/web/20120330105926/http://www.iso.org/iso/iso_3166-2_newsletter_i-8_en.pdf)"
}
]
}
Directories
/docs
- documentation foriso3166-updates
Python package./iso3166_updates
- source code foriso3166-updates
Python package./iso3166-updates-api
- all code and files related to the serverless Google Cloud Function for theiso3166-updates
API, including the main.py, requirements.txt and API config file./iso3166-check-for-updates
- all code and files related to the serverless Google Cloud Function for the check-for-updates function which is a periodically called Cloud Function that uses the Python software to check for the latest updates for all country's, ensuring the API and jsons are reliable and up-to-date. Includes the main.py and requirements.txt files./tests
- unit and integration tests foriso3166-updates
.
Issues
Any issues, errors or bugs can be raised via the Issues tab in the repository. Also if there are any missing or incorrect data in the updates json, this should also be raised by creating an issue.
Contact
If you have any questions or comments, please contact amckenna41@qub.ac.uk or raise an issue on the Issues tab.
References
[1]: ISO3166-1: https://en.wikipedia.org/wiki/ISO_3166-1
[2]: ISO3166-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]: ISO3166-1 flag-icons repo: https://github.com/lipis/flag-icons
[6]: ISO3166-2 flag-icons repo: https://github.com/amckenna41/iso3166-flag-icons
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for iso3166_updates-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 369dc2dde40542378b80521716051ef9a73f4ff9f56090dd4f18b2df47d294bc |
|
MD5 | 12e49269bb874ee1d6264eb2f092c50c |
|
BLAKE2b-256 | 8fef07fd2a39778e90f529de22a0f284533e51c8f87801f778efa4b7dfd82c50 |