Comprehensive country codes: ISO 3166, ITU, ISO 4217 currency codes and many more

core

Files Size Format Created Updated License Source
1 196kB csv Unicode Common Locale Data Repository (CLDR) Project United Nations Statistics Division SIX Interbank Clearing Ltd (on behalf of ISO) Statoids Geonames US Securities and Exchange Commission
Comprehensive country code information, including ISO 3166 codes, ITU dialing codes, ISO 4217 currency codes, and many others. Provided as a Tabular Data Package. Data Data comes from multiple sources as follows: Customary English short names are from Unicode Common Locale Data Repository (CLDR) read more
Download

Data Files

country-codes  

Field information

Field Name Order Type (Format) Description
name 1 string Country's customary English short name (CLDR)
official_name_en 2 string Country's official English short name
official_name_fr 3 string Country's offical French short name
ISO3166-1-Alpha-2 4 string Alpha-2 codes from ISO 3166-1
ISO3166-1-Alpha-3 5 string Alpha-3 codes from ISO 3166-1 (synonymous with World Bank Codes)
M49 6 number UN Statistics M49 numeric codes (nearly synonymous with ISO 3166-1 numeric codes, which are based on UN M49. ISO 3166-1 does not include Channel Islands or Sark, for example)
ITU 7 string Codes assigned by the International Telecommunications Union
MARC 8 string MAchine-Readable Cataloging codes from the Library of Congress
WMO 9 string Country abbreviations by the World Meteorological Organization
DS 10 string Distinguishing signs of vehicles in international traffic
Dial 11 string Country code from ITU-T recommendation E.164, sometimes followed by area code
FIFA 12 string Codes assigned by the Fédération Internationale de Football Association
FIPS 13 string Codes from the U.S. standard FIPS PUB 10-4
GAUL 14 string Global Administrative Unit Layers from the Food and Agriculture Organization
IOC 15 string Codes assigned by the International Olympics Committee
ISO4217-currency_alphabetic_code 16 string ISO 4217 currency alphabetic code
ISO4217-currency_country_name 17 string ISO 4217 country name
ISO4217-currency_minor_unit 18 number ISO 4217 currency number of minor units
ISO4217-currency_name 19 string ISO 4217 currency name
ISO4217-currency_numeric_code 20 number ISO 4217 currency numeric code
is_independent 21 string Country status, based on the CIA World Factbook
Capital 22 string Capital city from Geonames
Continent 23 string Continent from Geonames
TLD 24 string Top level domain from Geonames
Languages 25 string Languages from Geonames
Geoname ID 26 number Geoname ID
EDGAR 27 string EDGAR country code from SEC

Read me

Comprehensive country code information, including ISO 3166 codes, ITU dialing codes, ISO 4217 currency codes, and many others. Provided as a Tabular Data Package.

Data

Data comes from multiple sources as follows:

Customary English short names are from Unicode Common Locale Data Repository (CLDR) Project.

Note: CLDR shorter names “ZZ-alt-short” are used when available

ISO 3166 official English and French short names are from United Nations Statistics Division

ISO 4217 currency codes are from currency-iso.org

Many other country codes are from statoids.com

Special thanks to Gwillim Law for his excellent statoids.com site (some of the field descriptions are excerpted from his site), which is more up-to-date than most similar resources and is much easier to scrape than multiple Wikipedia pages.

Capital cities, languages, continents, TLDs, and geonameid are from geonames.org

EDGAR codes are from sec.gov

Preparation

This package includes Python scripts to fetch current country information and output a JSON document and CSV of combined country code information.

CSV output is provided via the in2csv and csvcut utilities from csvkit

data/country-codes.csv

Install requirements:

pip install -r scripts/requirements.pip

Run GNU Make to generate data file:

make country-codes.csv

License

This material is licensed by its maintainers under the Public Domain Dedication and License.

Nevertheless, it should be noted that this material is ultimately sourced from ISO and other standards bodies and their rights and licensing policies are somewhat unclear. As this is a short, simple database of facts there is a strong argument that no rights can subsist in this collection. However, ISO state on their site:

ISO makes the list of alpha-2 country codes available for internal use and non-commercial purposes free of charge.

This carries the implication (though not spelled out) that other uses are not permitted and that, therefore, there may be rights preventing further general use and reuse.

If you intended to use these data in a public or commercial product, please check the original sources for any specific restrictions.

Import into your tool

In order to use Data Package in R follow instructions below:

install.packages("devtools")
library(devtools)
install_github("hadley/readr")
install_github("ropenscilabs/jsonvalidate")
install_github("ropenscilabs/datapkg")

#Load client
library(datapkg)

#Get Data Package
datapackage <- datapkg_read("https://pkgstore.datahub.io/core/country-codes/latest")

#Package info
print(datapackage)

#Open actual data in RStudio Viewer
View(datapackage$data$"country-codes")

Tested with Python 3.5.2

To generate Pandas data frames based on JSON Table Schema descriptors we have to install jsontableschema-pandas plugin. To load resources from a data package as Pandas data frames use datapackage.push_datapackage function. Storage works as a container for Pandas data frames.

In order to work with Data Packages in Pandas you need to install our packages:

$ pip install datapackage
$ pip install jsontableschema-pandas

To get Data Package run following code:

import datapackage

data_url = "https://pkgstore.datahub.io/core/country-codes/latest/datapackage.json"

# to load Data Package into storage
storage = datapackage.push_datapackage(data_url, 'pandas')

# to see datasets in this package
storage.buckets

# you can access datasets inside storage, e.g. the first one:
storage[storage.buckets[0]]

In order to work with Data Packages in Python you need to install our packages:

$ pip install datapackage

To get Data Package into your Python environment, run following code:

import datapackage

dp = datapackage.DataPackage('https://pkgstore.datahub.io/core/country-codes/latest/datapackage.json')

# see metadata
print(dp.descriptor)

# get list of csv files
csvList = [dp.resources[x].descriptor['name'] for x in range(0,len(dp.resources))]
print(csvList) # ["resource name", ...]

# access csv file by the index starting 0
print(dp.resources[0].data)

To use this Data Package in JavaScript, please, follow instructions below:

Install datapackage using npm:

$ npm install [email protected]

Once the package is installed, use code snippet below


const Datapackage = require('datapackage').Datapackage

async function fetchDataPackageAndData(dataPackageIdentifier) {
  const dp = await new Datapackage(dataPackageIdentifier)
  await Promise.all(dp.resources.map(async (resource) => {
    if (resource.descriptor.format === 'geojson') {
      const baseUrl = resource._basePath.replace('/datapackage.json', '')
      const resourceUrl = `${baseUrl}/${resource._descriptor.path}`
      const response = await fetch(resourceUrl)
      resource.descriptor._values = await response.json()
    } else {
      // we assume resource is tabular for now ...
      const table = await resource.table
      // rows are simple arrays -- we can convert to objects elsewhere as needed
      const rowsAsObjects = false
      resource.descriptor._values = await table.read(rowsAsObjects)
    }
  }))

  // see the data package object
  console.dir(dp)

  // data itself is stored in Resource object, e.g. to access first resource:
  console.log(dp.resources[0]._values)

  return dp
}


fetchDataPackageAndData('https://pkgstore.datahub.io/core/country-codes/latest/datapackage.json');

Our JavaScript is written using ES6 features. We are using node.js v7.4.0 and passing --harmony option to enable ES6:

$ node --harmony index.js

In order to work with Data Packages in SQL you need to install our packages:

$ pip install datapackage
$ pip install jsontableschema-sql
$ pip install sqlalchemy

To import Data Package to your SQLite Database, run following code:

import datapackage
from sqlalchemy import create_engine

data_url = 'https://pkgstore.datahub.io/core/country-codes/latest/datapackage.json'
engine = create_engine('sqlite:///:memory:')

# to load Data Package into storage
storage = datapackage.push_datapackage(data_url, 'sql', engine=engine)

# to see datasets in this package
storage.buckets

# to execute sql command (assuming data is in "data" folder, name of resource is data and file name is data.csv)
storage._Storage__connection.execute('select * from data__data___data limit 1;').fetchall()

# description of the table columns
storage.describe('data__data___data')
Datapackage.json