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
: Afrikaansam
: Amharicar
: Arabicaz
: Azerbaijanibe
: Belorussianbg
: Bulgarianbn
: Bengalibs
: Bosnianca
: Catalancs
: Czechcy
: Cymraegda
: Danishde
: Germandv
: Dhivehien
: Englishes
: Spanishet
: Estonianeu
: Basquefa
: Persianfi
: Finnishfr
: Frenchgl
: Galicianel
: Greekha
: Hausahe
: Hebrewhi
: Hindihr
: Croatianhu
: Hungarianhy
: Armenianis
: Icelandicit
: Italianid
: Indonesianja
: Japaneseka
: Georgiankk
: Kazakhkm
: Khmerko
: Koreanku
: Kurdishky
: Kyrgyzlt
: Lithuanianlv
: Latvianmk
: Macedonianml
: Malayalammn
: Mongolianms
: Malaynb
: Norwegian Bokmålnl
: Dutchnn
: Norwegian Nynorskno
: Norwegianpl
: Polishps
: Pashtopt
: Portuguesero
: Romanianru
: Russiansd
: Sindhisk
: Slovaksl
: Sloveneso
: Somalisq
: Albaniansr
: Serbiansv
: Swedishsw
: Swahilita
: Tamiltg
: Tajikth
: Thaitr
: Turkishtt
: Tatarug
: Uyghuruk
: Ukrainianur
: Urduuz
: Uzbekzh
: Chinesevi
: Vietnamese
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
Release history Release notifications | RSS feed
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)
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f06364c00ee299e0589097649ef97ae9bf05a583daa961efe727466f321f2d4 |
|
MD5 | cece35275a7502599753d3499fc6cfe1 |
|
BLAKE2b-256 | ef926e58bb1b3161e315663890a2adfb89aca7885755a1f4b8ef26b6a66eec3d |