World countries
available in multiple languages, in CSV, JSON, PHP, SQL and XML formats, with associated codes as defined by the ISO 3166 standard, and with national flags included
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
, SQL
and XML
formats, in multiple languages and with national flags included.
In the language folders you will find files named in two different ways. Here's what you will find in each of them:
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 195 entries made up from the 193 sovereign states (commonly referred to as countries) that are members of the United Nations (UN) plus the 2 observer states of Palestine and the Vatican City State. |
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 29 languages:
- Arabic
- Basque
- Bulgarian
- Chinese (Simplified)
- Chinese (Traditional)
- Czech
- Danish
- Dutch
- English
- Estonian
- Finnish
- French
- German
- Greek
- Hungarian
- Italian
- Japanese
- Korean
- Lithuanian
- Norwegian
- Polish
- Portuguese
- Romanian
- Russian
- Slovak
- Spanish
- Swedish
- Thai
- Ukrainian
The language folders are named based on the ISO 639-1 standard.
🎂 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! 🎉
Installation
The lists are available as a npm package. To install it use:
npm install world_countries_lists --save
You can install the lists via Composer
composer require stefangabos/world_countries
Alternatively, you can load data from JSDelivr CDN like this:
<script src="https://cdn.jsdelivr.net/npm/world_countries_lists@latest/data/en/countries.json"></script>
Or
download a customized build.
Data formats
SQL
Excerpt from the data/en/countries.sql
file:
(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'),
CSV
Excerpt from the data/en/countries.csv
file:
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/en/countries.json
file:
{"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
function search_country(query) {
if (undefined === query.id && undefined === query.alpha2 && undefined === query.alpha3) return undefined;
return countries.filter(function(country) {
return (
(undefined !== query.id && parseInt(country.id, 10) === parseInt(query.id, 10))
|| (undefined !== query.alpha2 && country.alpha2 === query.alpha2.toLowerCase())
|| (undefined !== query.alpha3 && country.alpha3 === query.alpha3.toLowerCase())
)
}).pop()
}
Usage
search_county({id: 250})
search_county({alpha2: 'fr'})
search_county({alpha3: 'fra'})
PHP
Excerpt from the data/en/countries.php
file:
...
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
require 'path/to/countries.php';
function search_country($query) {
global $countries;
if (!isset($query['id']) && !isset($query['alpha2']) && !isset($query['alpha3'])) return false;
$result = array_filter($countries, function($country) use ($query) {
// return country's data if
return (
// we are searching by ID and we have a match
(isset($query['id']) && $country['id'] == $query['id'])
// or we are searching by alpha2 and we have a match
|| (isset($query['alpha2']) && $country['alpha2'] == strtolower($query['alpha2']))
// or we are searching by alpha3 and we have a match
|| (isset($query['alpha3']) && $country['alpha3'] == strtolower($query['alpha3']))
);
});
return empty($result) ? false : array_pop($result);
}
Usage
search_county(array('id' => 250});
search_county(array('alpha2' => 'fr'});
search_county(array('alpha3' => 'fra'});
XML
Excerpt from the data/en/countries.xml
file:
<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"/>
Flags
The package also contains the national flags of each country as a 16x16, 24x24, 32x32, 48x48, 64x64 and 128x128 PNG images, courtesy of IconDrawer. The image files are named using the ISO 3166-1-alpha-2 code of the country they represent, for easily pairing flags with countries.
Flag images are also available as single JSON
files, one for each of the available sizes, containing all flag images as data-uri
Data sources
Country names in all languages are taken from Wikipedia.