Skip to main content

i18n for ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes

Project description

py-i18n-countries

i18n for ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes from: Wiki

Install

pip install i18n-iso-countries

Code to Country

Get the name of a country by its ISO 3166-1 Alpha-2, Alpha-3 or Numeric code

from i18n_iso_countries import get_country_name

get_country_name(code="US", language='en') # United States of America
get_country_name(code="US", language='de') # Vereinigte Staaten von Amerika
get_country_name(code="USA", language='en') # United States of America
get_country_name(code="840", language='en') # United States of America

Get aliases/short name using select

from i18n_iso_countries import get_country_name

# Some countries have alias/short names defined. `select` is used to control which
# name will be returned.
get_country_name(code="GB", language='en', select="official") # United Kingdom
get_country_name(code="GB", language='en', select="alias") # UK
get_country_name(code="GB", language='en', select="all") # ["United Kingdom", "UK", "Great Britain"]

# Countries without an alias will always return the offical name
get_country_name(code="LT", language='en', select="official") # Lithuania
get_country_name(code="LT", language='de', select="alias") # Lithuania
get_country_name(code="LT", language='en', select="all") # ["Lithuania"]

Get all names by their ISO 3166-1 Alpha-2 code

from i18n_iso_countries import get_country_name

get_country_name(language='en', select="official") # { 'AF': 'Afghanistan', 'AL': 'Albania', [...], 'ZM': 'Zambia', 'ZW': 'Zimbabwe' }

Get all supported languages (ISO 639-1)

from i18n_iso_countries import get_supported_languages
get_supported_languages() # ["cy", "dv", "sw", "eu", "af", "am", ...]

Supported languages (ISO 639-1)

In case you want to add new language, please refer [ISO 639-1 table][iso:639-1].

  • af: Afrikaans
  • am: Amharic
  • ar: Arabic
  • az: Azerbaijani
  • be: Belorussian
  • bg: Bulgarian
  • bn: Bengali
  • bs: Bosnian
  • ca: Catalan
  • cs: Czech
  • cy: Cymraeg
  • da: Danish
  • de: German
  • dv: Dhivehi
  • en: English
  • es: Spanish
  • et: Estonian
  • eu: Basque
  • fa: Persian
  • fi: Finnish
  • fr: French
  • gl: Galician
  • el: Greek
  • ha: Hausa
  • he: Hebrew
  • hi: Hindi
  • hr: Croatian
  • hu: Hungarian
  • hy: Armenian
  • is: Icelandic
  • it: Italian
  • id: Indonesian
  • ja: Japanese
  • ka: Georgian
  • kk: Kazakh
  • km: Khmer
  • ko: Korean
  • ku: Kurdish
  • ky: Kyrgyz
  • lt: Lithuanian
  • lv: Latvian
  • mk: Macedonian
  • ml: Malayalam
  • mn: Mongolian
  • ms: Malay
  • nb: Norwegian Bokmål
  • nl: Dutch
  • nn: Norwegian Nynorsk
  • no: Norwegian
  • pl: Polish
  • ps: Pashto
  • pt: Portuguese
  • ro: Romanian
  • ru: Russian
  • sd: Sindhi
  • sk: Slovak
  • sl: Slovene
  • so: Somali
  • sq: Albanian
  • sr: Serbian
  • sv: Swedish
  • sw: Swahili
  • ta: Tamil
  • tg: Tajik
  • th: Thai
  • tr: Turkish
  • tt: Tatar
  • ug: Uyghur
  • uk: Ukrainian
  • ur: Urdu
  • uz: Uzbek
  • zh: Chinese
  • vi: Vietnamese

List of ISO 639-1 codes

Codes

Convert Alpha-3 to Alpha-2 code

from i18n_iso_countries import alpha3_to_alpha2

alpha3_to_alpha2('USA') #US

Convert Numeric to Alpha-2 code

from i18n_iso_countries import numeric_to_alpha2

numeric_to_alpha2('840') # US

Convert Alpha-2 to Alpha-3 code

from i18n_iso_countries import alpha2_to_alpha3

alpha2_to_alpha3('DE') # DEU

Convert Numeric to Alpha-3 code

from i18n_iso_countries import numeric_to_alpha3

numeric_to_alpha3('840') # USA

Convert Alpha-3 to Numeric code

from i18n_iso_countries import alpha3_to_numeric

alpha3_to_numeric('SWE') #752

Convert Alpha-2 to Numeric code

from i18n_iso_countries import alpha2_to_numeric

alpha2_to_numeric("SE") # 752

Get all Alpha-2 codes

from i18n_iso_countries import get_alpha2_codes

get_alpha2_codes() # { 'AF': 'AFG', 'AX': 'ALA', [...], 'ZM': 'ZMB', 'ZW': 'ZWE' }

Get all Alpha-3 codes

from i18n_iso_countries import get_alpha3_codes

get_alpha3_codes() # { 'AFG': 'AF', 'ALA': 'AX', [...], 'ZMB': 'ZM', 'ZWE': 'ZW' }

Get all Numeric codes

from i18n_iso_countries import get_numeric_codes

get_numeric_codes() # { '004': 'AF', '008': 'AL', [...], '887': 'YE', '894': 'ZM' }

Validate country code

from i18n_iso_countries import is_valid_country_code

is_valid_country_code("US") # True
is_valid_country_code("USA") # True
is_valid_country_code("XX") # False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i18n-iso-countries-1.0.0.tar.gz (150.8 kB view details)

Uploaded Source

File details

Details for the file i18n-iso-countries-1.0.0.tar.gz.

File metadata

  • Download URL: i18n-iso-countries-1.0.0.tar.gz
  • Upload date:
  • Size: 150.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for i18n-iso-countries-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2f06364c00ee299e0589097649ef97ae9bf05a583daa961efe727466f321f2d4
MD5 cece35275a7502599753d3499fc6cfe1
BLAKE2b-256 ef926e58bb1b3161e315663890a2adfb89aca7885755a1f4b8ef26b6a66eec3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page