Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

world_countries

> 数据库
Open source

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CS

1.6K stars0 likes3 views
WebsiteGitHub

About

Constantly updated lists of world countries and their associated alpha-2, alpha-3 and numeric country codes as defined by the ISO 3166 standard, available in CS

World countries  

available in multiple languages, in CSV, JSON, PHP, MySQL, MSSQL and XML formats, with associated codes as defined by the ISO 3166 standard, and with national flags included; also available are the ISO 3166-2 codes used for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1

Constantly updated lists of world countries, territories and areas of geographical interest, with associated alpha-2, alpha-3 and numeric codes as defined by the ISO 3166-1 standard, published and maintained by the International Organization for Standardization, available in CSV, JSON, PHP, MySQL, MSSQL and XML formats, in multiple languages and with national flags included. Also available are the ISO 3166-2 codes used for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1.

In the language folders (inside data/countries) you will find files named in two different ways:

File names Content
world.* Files named like this contain all the 249 countries, territories, and areas of geographical interest that have an officially assigned ISO 3166-1 code.
countries.* Files named like this contain the 193 sovereign states (commonly referred to as countries) that are members of the United Nations (UN) .

Note that there are 206 sovereign states in the world, the 11 states that are missing from the countries list being the ones having their sovereignty disputed. See the list of sovereign states with information on their status and recognition of their sovereignty.

The files contain:

  • the ISO 3166-1 numeric country codes
  • the ISO 3166 official short names in English1
  • the ISO 3166-1 alpha-2 two-letter country codes2
  • the ISO 3166-1 alpha-3 three-letter country codes2

1 for other languages the country names are in that particular language
2 ISO 3166-1 alpha codes are uppercase but this library provides them in lowercase

The lists are currently available in 37 languages:

  • Arabic
  • Armenian
  • Basque
  • Breton
  • Bulgarian
  • Chinese (Simplified)
  • Chinese (Traditional)
  • Croatian
  • Czech
  • Danish
  • Dutch
  • English
  • Esperanto
  • Estonian
  • Farsi
  • Finnish
  • French
  • German
  • Greek
  • Hungarian
  • Italian
  • Japanese
  • Korean
  • Lithuanian
  • Norwegian
  • Polish
  • Portuguese
  • Romanian
  • Russian
  • Serbian
  • Slovak
  • Slovenian
  • Spanish
  • Swedish
  • Thai
  • Turkish
  • Ukrainian

The language folders are named based on the ISO 639-1 standard.

ISO 3166-2 codes

The project also tries to be a comprehensive and up-to-date source for ISO 3166-2 which defines codes for identifying the principal subdivisions (e.g., provinces or states) of all countries coded in ISO 3166-1.

The purpose of ISO 3166-2 is to establish an international standard of short and unique alphanumeric codes to represent the relevant administrative divisions and dependent territories of all countries in a more convenient and less ambiguous form than their full names. Each complete ISO 3166-2 code consists of two parts, separated by a hyphen:

US-TX for Texas, USA

The first part is the ISO 3166-1 alpha-2 code of the country; The second part is a string of up to three alphanumeric characters, which is usually obtained from national sources and stems from coding systems already in use in the country concerned, but may also be developed by the ISO itself. Each complete ISO 3166-2 code can then be used to uniquely identify a country subdivision in a global context.

The list is available in CSV, JSON, PHP, MySQL, MSSQL and XML formats in the data/subdivisions folder and the lists contain:

  • the country code
  • the ISO 3166-2 subdivision code
  • the ISO 3166-2 subdivision name
  • the subdivision name in english (where available)
  • the subdivision type
  • the parent (for when there are multiple administrative levels)

An excerpt from the CSV file looks like this

csv
US,US-AL,Alabama,,state,
US,US-AK,Alaska,,state,
US,US-AZ,Arizona,,state,
US,US-AR,Arkansas,,state,
US,US-CA,California,,state,
US,US-CO,Colorado,,state,

Note that english name for subdivisions is not available for all and also that it is not duplicated if the original ISO 3166-2 name is already in english!

License

The country and subdivision data is sourced from Wikipedia's ISO 3166-1 pages and Wikipedia's ISO 3166-2 pages, and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.

Flags

The package also contains the national flags of each country in multiple styles. The image files are named using the ISO 3166-1-alpha-2 code of the country they represent, for easily pairing flags with countries.


In /data/flags/default/ you will find 16x16, 24x24, 32x32, 48x48, 64x64 and 128x128 PNG images looking like the ones below. The images were available for free on the now defunct icondrawer.com


In /data/flags/flat/ you will find 16x12, 24x18, 32x24, 48x36, 64x48 and 128x96 PNG images looking like the ones below. The images are taken from the AWESOME https://github.com/lipis/flag-icons.


In /data/flags/flat-waving/ you will find 16x12, 24x18, 32x24, 48x36, 64x48 and 128x96 PNG images looking like the ones below. The images are taken from flagpedia.net


Flag images are also available as single JSON files, one for each of the available sizes, containing all flag images as data-uri

Support the development of this project

Your support means a lot and it keeps me motivated to keep working on open source projects.
If you like this project please ⭐ it by clicking on the star button at the top of the page.
If you are feeling generous, you can buy me a coffee by donating through PayPal, or you can become a sponsor.
Either way - Thank you!

I also run PageDrop — if you need a fast, professional website for your business, check it out.

Installation

The lists are available as a npm package. To install it use:

bash
# the "--save" argument adds the plugin as a dependency in packages.json
npm install world_countries_lists --save

You can install the lists via Composer

bash
composer require stefangabos/world_countries

Alternatively, you can load data from JSDelivr CDN like this:

xml
<script src="https://cdn.jsdelivr.net/npm/world_countries_lists@latest/data/countries/en/countries.json"></script>

Or

download a customized build.

Data formats

MySQL

Excerpt from the data/countries/en/countries.sql file:

(the columns are id,alpha2,alpha3,name)

sql
(250,'fr','fra','France'),
(266,'ga','gab','Gabon'),
(270,'gm','gmb','Gambia'),
(268,'ge','geo','Georgia'),
(276,'de','deu','Germany'),
(288,'gh','gha','Ghana'),
(300,'gr','grc','Greece'),
(308,'gd','grd','Grenada'),

MSSQL

Excerpt from the data/countries/en/countries-mssql.sql file:

(the columns are id,alpha2,alpha3,name)

sql
(250,'fr','fra',N'France'),
(266,'ga','gab',N'Gabon'),
(270,'gm','gmb',N'Gambia'),
(268,'ge','geo',N'Georgia'),
(276,'de','deu',N'Germany'),
(288,'gh','gha',N'Ghana'),
(300,'gr','grc',N'Greece'),
(308,'gd','grd',N'Grenada'),

CSV

Excerpt from the data/countries/en/countries.csv file:

(the columns are id,alpha2,alpha3,name)

csv
250,fr,fra,France
266,ga,gab,Gabon
270,gm,gmb,Gambia
268,ge,geo,Georgia
276,de,deu,Germany
288,gh,gha,Ghana
300,gr,grc,Greece
308,gd,grd,Grenada

JSON

Excerpt from the data/countries/en/countries.json file:

json
{"id":250,"alpha2":"fr","alpha3":"fra","name":"France"},
{"id":266,"alpha2":"ga","alpha3":"gab","name":"Gabon"},
{"id":270,"alpha2":"gm","alpha3":"gmb","name":"Gambia"},
{"id":268,"alpha2":"ge","alpha3":"geo","name":"Georgia"},
{"id":276,"alpha2":"de","alpha3":"deu","name":"Germany"},
{"id":288,"alpha2":"gh","alpha3":"gha","name":"Ghana"},
{"id":300,"alpha2":"gr","alpha3":"grc","name":"Greece"},
{"id":308,"alpha2":"gd","alpha3":"grd","name":"Grenada"},

Here's a little helper function for searching for a specific country's data

The helper function assumes that the JSON with the countries data is associated with a variable named countries which is in the same scope as the function

The helper function is to be used with the non-combined data sets.
For the combined data sets you can write the function yourself.

…

Usage

javascript
search_country({id: 250})
search_country({alpha2: 'fr'})
search_country({alpha3: 'fra'})

TypeScript

Typings are available (source):

typescript
import { Country, LanguageCode, TranslatedCountry } from 'world_countries_lists'

PHP

Excerpt from the data/countries/en/countries.php file:

php
250 => array('id' => 250, 'alpha2' => 'fr', 'alpha3' => 'fra', 'name' => 'France'),
266 => array('id' => 266, 'alpha2' => 'ga', 'alpha3' => 'gab', 'name' => 'Gabon'),
270 => array('id' => 270, 'alpha2' => 'gm', 'alpha3' => 'gmb', 'name' => 'Gambia'),

Here's a little helper function for searching for a specific country's data

The helper function is to be used with the non-combined data sets.
For the combined data sets you can write the function yourself.

…

Usage

php
search_country(array('id' => 250));
search_country(array('alpha2' => 'fr'));
search_country(array('alpha3' => 'fra'));

XML

Excerpt from the data/countries/en/countries.xml file:

xml
<country id="250" alpha2="fr" alpha3="fra" name="France"/>
<country id="266" alpha2="ga" alpha3="gab" name="Gabon"/>
<country id="270" alpha2="gm" alpha3="gmb" name="Gambia"/>
<country id="268" alpha2="ge" alpha3="geo" name="Georgia"/>
<country id="276" alpha2="de" alpha3="deu" name="Germany"/>
<country id="288" alpha2="gh" alpha3="gha" name="Ghana"/>
<country id="300" alpha2="gr" alpha3="grc" name="Greece"/>
<country id="308" alpha2="gd" alpha3="grd" name="Grenada"/>

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPcountriescsvflagsiso-3166-1

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库