Convert Figma logo to code with AI

stefangabos logoworld_countries

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 CSV, JSON , PHP, SQL and XML formats, in multiple languages and with national flags included; also available are the ISO 3166-2 codes of provinces/ states associated with the countries

1,469
386
1,469
8

Top Related Projects

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Countries, Languages & Continents data (capital and currency, native name, calling codes).

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

Quick Overview

The stefangabos/world_countries repository is a comprehensive collection of world countries data, including names, codes, and flags. It provides this information in various formats such as CSV, JSON, SQL, and XML, making it a versatile resource for developers and data enthusiasts working on projects that require country-related information.

Pros

  • Offers data in multiple formats (CSV, JSON, SQL, XML) for easy integration into different projects
  • Includes country names in multiple languages, enhancing internationalization support
  • Provides both 2-letter and 3-letter country codes, as well as numeric codes
  • Regularly updated to reflect changes in country information

Cons

  • Limited additional data beyond basic country information (e.g., no population or geographical data)
  • May require manual updates in projects to stay current with the latest changes
  • Lacks detailed documentation on data sources and update frequency
  • Some less common or disputed territories might be missing or inconsistently represented

Code Examples

Since this is not a code library but a data repository, there are no specific code examples to provide. However, here's a brief example of how you might use the data in a Python script:

import json

# Load the JSON data
with open('data/countries.json', 'r') as f:
    countries_data = json.load(f)

# Print the name and capital of each country
for country in countries_data:
    print(f"Country: {country['name']}, Capital: {country['capital']}")

Getting Started

To use this data in your project:

  1. Clone the repository or download the desired data files.
  2. Choose the format that best suits your needs (CSV, JSON, SQL, or XML).
  3. Import the data into your project using appropriate methods for the chosen format.
  4. Use the data as needed in your application or analysis.

For example, to use the JSON data in a JavaScript project:

fetch('path/to/countries.json')
  .then(response => response.json())
  .then(data => {
    // Use the data in your application
    console.log(data);
  })
  .catch(error => console.error('Error loading country data:', error));

Competitor Comparisons

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.

Pros of countries

  • More comprehensive data, including additional fields like currencies, languages, and timezones
  • Regularly updated with more frequent commits
  • Provides a Laravel package for easy integration with Laravel projects

Cons of countries

  • Larger file size due to more detailed information
  • May be overly complex for simple use cases
  • Requires more setup and configuration compared to world_countries

Code comparison

world_countries:

{
  "id": "US",
  "name": "United States",
  "alpha2": "US",
  "alpha3": "USA"
}

countries:

[
    'name' => 'United States',
    'alpha2' => 'US',
    'alpha3' => 'USA',
    'currency' => 'USD',
    'calling_code' => '1',
    'capital' => 'Washington D.C.',
    'timezones' => ['America/New_York', 'America/Chicago', ...],
    'languages' => ['en'],
]

Summary

world_countries is simpler and more lightweight, making it ideal for basic country information needs. countries offers a more comprehensive dataset and Laravel integration but comes with increased complexity and file size. The choice between the two depends on the specific requirements of your project and the level of detail needed for country data.

🌍 Discover our global repository of countries, states, and cities! 🏙️ Get comprehensive data in JSON, SQL, PSQL, SQLSERVER, MONGODB, SQLITE, XML, YAML, and CSV formats. Access ISO2, ISO3 codes, country code, capital, native language, timezones (for countries), and more. #countries #states #cities

Pros of countries-states-cities-database

  • More comprehensive data, including states and cities
  • Regularly updated with community contributions
  • Available in multiple formats (JSON, SQL, CSV, XML)

Cons of countries-states-cities-database

  • Larger file size due to more detailed information
  • May require more processing for simple country-only use cases
  • Potential for inconsistencies in city/state data across countries

Code Comparison

countries-states-cities-database:

{
  "id": 101,
  "name": "India",
  "iso3": "IND",
  "iso2": "IN",
  "numeric_code": "356",
  "phone_code": "91",
  "capital": "New Delhi",
  "currency": "INR",
  "currency_name": "Indian rupee",
  "currency_symbol": "₹",
  "tld": ".in",
  "native": "भारत",
  "region": "Asia",
  "subregion": "Southern Asia",
  "timezones": [
    {
      "zoneName": "Asia/Kolkata",
      "gmtOffset": 19800,
      "gmtOffsetName": "UTC+05:30",
      "abbreviation": "IST",
      "tzName": "Indian Standard Time"
    }
  ],
  "translations": {
    "kr": "인도",
    "pt-BR": "Índia",
    "pt": "Índia",
    "nl": "India",
    "hr": "Indija",
    "fa": "هند",
    "de": "Indien",
    "es": "India",
    "fr": "Inde",
    "ja": "インド",
    "it": "India",
    "cn": "印度"
  },
  "latitude": "20.00000000",
  "longitude": "77.00000000",
  "emoji": "🇮🇳",
  "emojiU": "U+1F1EE U+1F1F3"
}

world_countries:

{
  "id": 356,
  "name": "India",
  "alpha2": "IN",
  "alpha3": "IND"
}

Countries, Languages & Continents data (capital and currency, native name, calling codes).

Pros of Countries

  • Includes more detailed data such as languages, currencies, and emoji flags
  • Provides data in multiple formats (JSON, CSV, SQL)
  • Offers a command-line interface for easy data access

Cons of Countries

  • Less frequently updated (last update over a year ago)
  • Fewer contributors and stars on GitHub
  • Limited documentation on data sources and update processes

Code Comparison

Countries:

{
  "name": "United States",
  "alpha2": "US",
  "alpha3": "USA",
  "numeric": "840",
  "locales": ["en-US"],
  "default_locale": "en-US",
  "currency": "USD",
  "languages": ["en"],
  "capital": "Washington D.C.",
  "emoji": "🇺🇸",
  "emojiU": "U+1F1FA U+1F1F8"
}

world_countries:

{
  "id": 840,
  "name": "United States",
  "alpha2": "US",
  "alpha3": "USA"
}

Countries offers more comprehensive data for each country, including languages, currency, and emoji representations. world_countries provides a simpler structure with basic country information. The choice between the two repositories depends on the specific data requirements of the project and the need for additional details beyond standard country codes.

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

Pros of country-list

  • Offers data in multiple formats (CSV, JSON, SQL, XML, etc.)
  • Supports a vast number of languages (over 200)
  • Includes additional data like country codes and currency information

Cons of country-list

  • Large repository size due to multiple formats and languages
  • May require more processing to extract specific data
  • Less focused on geographical data (e.g., capitals, coordinates)

Code Comparison

world_countries (JSON format):

{
  "AF": {
    "alpha2": "AF",
    "alpha3": "AFG",
    "name": "Afghanistan",
    "numeric": "004",
    "latitude": 33,
    "longitude": 65
  }
}

country-list (PHP format):

return array(
    'AF' => 'Afghanistan',
    'AX' => 'Åland Islands',
    'AL' => 'Albania',
    'DZ' => 'Algeria',
    'AS' => 'American Samoa',
);

Summary

world_countries focuses on providing comprehensive geographical data for countries, including coordinates and regional information. It offers a more streamlined approach with fewer file formats.

country-list excels in language support and data format variety, making it suitable for projects requiring multilingual country names or specific data formats. However, it may require additional processing to extract specific information and has a larger repository size.

Choose based on your project's specific needs for language support, data formats, and geographical information.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

zebrajs

World countries  Tweet

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

npm Total Monthly JSDelivr License

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 namesContent
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 type
  • the parent (for when there are multiple administrative levels)

An excerpt from the CSV file looks like this

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,

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! 🎉

Star it on GitHub Donate

Installation

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

# 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

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/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)

(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)

(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)

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:

{"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.

//  returns an object with the sought country's data if the search yields a result
//  returns undefined if no results could be found or if argument is incorrect
function search_country(query) {

    // if argument is not valid return false
    if (undefined === query.id && undefined === query.alpha2 && undefined === query.alpha3) return undefined;

        // iterate over the array of countries
	return countries.filter(function(country) {

        // return country's data if
        return (
            // we are searching by ID and we have a match
            (undefined !== query.id && parseInt(country.id, 10) === parseInt(query.id, 10))
            // or we are searching by alpha2 and we have a match
            || (undefined !== query.alpha2 && country.alpha2 === query.alpha2.toLowerCase())
            // or we are searching by alpha3 and we have a match
            || (undefined !== query.alpha3 && country.alpha3 === query.alpha3.toLowerCase())
        )

    // since "filter" returns an array we use pop to get just the data object
    }).pop()

}

Usage

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

TypeScript

Typings are available (source):

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

PHP

Excerpt from the data/countries/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

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

//  this function assumes that you have done this:
$countries = require 'path/to/countries.php';

//  returns an array with the sought country's data if the search yields a result
//  returns false if no results could be found or if argument is incorrect
function search_country($query) {

    // make the countries available in the function
    global $countries;

    // if argument is not valid return false
    if (!isset($query['id']) && !isset($query['alpha2']) && !isset($query['alpha3'])) return false;

    // iterate over the array of countries
    $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']))
        );

    });

    // since "array_filter" returns an array we use pop to get just the data object
    // we return false if a result was not found
    return empty($result) ? false : array_pop($result);

}

Usage

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:

<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"/>