Package: i18n-iso-countries
py-i18n-countriesi18n for ISO 3166-1 country codes. We support Alpha-2, Alpha-3 and Numeric codes from:WikiInstallpip install i18n-iso-countriesCode to CountryGet the name of a country by its ISO 3166-1 Alpha-2, Alpha-3 or Numeric codefromi18n_iso_countriesimportget_country_nameget_country_name(code="US",language='en')# United States of Americaget_country_name(code="US",language='de')# Vereinigte Staaten von Amerikaget_country_name(code="USA",language='en')# United States of Americaget_country_name(code="840",language='en')# United States of AmericaGet aliases/short name using selectfromi18n_iso_countriesimportget_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 Kingdomget_country_name(code="GB",language='en',select="alias")# UKget_country_name(code="GB",language='en',select="all")# ["United Kingdom", "UK", "Great Britain"]# Countries without an alias will always return the offical nameget_country_name(code="LT",language='en',select="official")# Lithuaniaget_country_name(code="LT",language='de',select="alias")# Lithuaniaget_country_name(code="LT",language='en',select="all")# ["Lithuania"]Get all names by their ISO 3166-1 Alpha-2 codefromi18n_iso_countriesimportget_country_nameget_country_name(language='en',select="official")# { 'AF': 'Afghanistan', 'AL': 'Albania', [...], 'ZM': 'Zambia', 'ZW': 'Zimbabwe' }Get all supported languages (ISO 639-1)fromi18n_iso_countriesimportget_supported_languagesget_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: VietnameseList of ISO 639-1 codesCodesConvert Alpha-3 to Alpha-2 codefromi18n_iso_countriesimportalpha3_to_alpha2alpha3_to_alpha2('USA')#USConvert Numeric to Alpha-2 codefromi18n_iso_countriesimportnumeric_to_alpha2numeric_to_alpha2('840')# USConvert Alpha-2 to Alpha-3 codefromi18n_iso_countriesimportalpha2_to_alpha3alpha2_to_alpha3('DE')# DEUConvert Numeric to Alpha-3 codefromi18n_iso_countriesimportnumeric_to_alpha3numeric_to_alpha3('840')# USAConvert Alpha-3 to Numeric codefromi18n_iso_countriesimportalpha3_to_numericalpha3_to_numeric('SWE')#752Convert Alpha-2 to Numeric codefromi18n_iso_countriesimportalpha2_to_numericalpha2_to_numeric("SE")# 752Get all Alpha-2 codesfromi18n_iso_countriesimportget_alpha2_codesget_alpha2_codes()# { 'AF': 'AFG', 'AX': 'ALA', [...], 'ZM': 'ZMB', 'ZW': 'ZWE' }Get all Alpha-3 codesfromi18n_iso_countriesimportget_alpha3_codesget_alpha3_codes()# { 'AFG': 'AF', 'ALA': 'AX', [...], 'ZMB': 'ZM', 'ZWE': 'ZW' }Get all Numeric codesfromi18n_iso_countriesimportget_numeric_codesget_numeric_codes()# { '004': 'AF', '008': 'AL', [...], '887': 'YE', '894': 'ZM' }Validate country codefromi18n_iso_countriesimportis_valid_country_codeis_valid_country_code("US")# Trueis_valid_country_code("USA")# Trueis_valid_country_code("XX")# False