Universal country data library with ISO codes, phone codes, flags, currencies, and languages.
pip install countrykitOr install from source:
cd packages/python
pip install -e .- 250 countries and territories with complete data
- ISO 3166-1 alpha-2, alpha-3, and numeric codes
- Phone calling codes
- SVG and emoji flags
- Currencies with symbols
- Languages
- Regions and subregions
- Fast O(1) lookups by ISO codes
- Zero dependencies
import countrykit
# Or import specific functions
from countrykit import get_country_by_iso2, get_countries_by_region# Get by ISO 3166-1 alpha-2 (2-letter)
usa = countrykit.get_country_by_iso2('US')
print(usa['name']) # "United States"
print(usa['calling_code']) # "+1"
# Get by ISO 3166-1 alpha-3 (3-letter)
gbr = countrykit.get_country_by_iso3('GBR')
print(gbr['name']) # "United Kingdom"# Countries with +1 calling code
countries = countrykit.get_countries_by_calling_code('+1')
for country in countries:
print(country['name'])
# Output: United States, Canada# All European countries
europe = countrykit.get_countries_by_region('Europe')
print(len(europe)) # Number of European countries
# All countries in Southern Asia
south_asia = countrykit.get_countries_by_subregion('Southern Asia')# All countries using Euro
euro_countries = countrykit.get_countries_by_currency('EUR')
for country in euro_countries:
print(country['name'])# All English-speaking countries
english_countries = countrykit.get_countries_by_language('en')
for country in english_countries:
print(country['name'])# Search by name or native name
results = countrykit.search_countries('united')
for country in results:
print(country['name'])
# Output: United States, United Kingdom, United Arab Emirates# All countries (list)
all_countries = countrykit.countries
print(len(all_countries))
# Fast lookup maps (dict)
by_iso2 = countrykit.countries_by_cca2
by_iso3 = countrykit.countries_by_cca3
by_phone = countrykit.countries_by_calling_code
# All currencies
currencies = countrykit.get_all_currencies()
# All languages
languages = countrykit.get_all_languages()
# All calling codes
calling_codes = countrykit.get_all_calling_codes()
# All regions
regions = countrykit.get_all_regions()
# All subregions
subregions = countrykit.get_all_subregions()Each country object contains:
{
"cca2": "US", # ISO 3166-1 alpha-2
"cca3": "USA", # ISO 3166-1 alpha-3
"ccn3": "840", # ISO 3166-1 numeric
"name": "United States", # Common name
"native_name": "United States", # Native name
"calling_code": "+1", # Phone calling code
"capital": "Washington, D.C.", # Capital city
"region": "Americas", # Region
"subregion": "Northern America", # Subregion
"tld": ".us", # Top-level domain
"currency": [ # Currencies (array)
{
"code": "USD",
"name": "United States Dollar",
"symbol": "$"
}
],
"languages": [ # Languages (array)
{
"code": "en",
"name": "English"
}
],
"flag": {
"emoji": "🇺🇸", # Flag emoji
"svg": "flags/US.svg" # SVG flag path
}
}get_country_by_iso2(code)- Get country by 2-letter ISO codeget_country_by_iso3(code)- Get country by 3-letter ISO codeget_countries_by_calling_code(code)- Get countries by phone codeget_countries_by_region(region)- Get countries by regionget_countries_by_subregion(subregion)- Get countries by subregionget_countries_by_currency(code)- Get countries by currency codeget_countries_by_language(code)- Get countries by language codesearch_countries(query)- Search countries by name
get_all_regions()- Get all unique regionsget_all_subregions()- Get all unique subregionsget_all_currencies()- Get all currencies with detailsget_all_languages()- Get all languages with detailsget_all_calling_codes()- Get all calling codes with mappings
countries- List of all country objectscountries_by_cca2- Dict for O(1) lookup by ISO2countries_by_cca3- Dict for O(1) lookup by ISO3countries_by_calling_code- Dict of countries grouped by phone codecurrencies- List of all currency objectslanguages- List of all language objectsdial_codes- List of all calling code objects
- Python 3.6+
- No external dependencies
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
Data is curated from official sources and updated regularly. Flag SVGs are from public domain sources.