A python module for returning data about countries, ISO info and states/provinces within them.
Run this code online by clicking this link
- countryinfo
- Module used in this repo belong to their respective owners and I or this repo does not claim any right over them.
Note : File "country_info.py" will not run on basic python idle, due to some limitations (unable to print bold characters). use another file "country_info1.py" to run it in basic idles
- .info()
- .provinces()
- .alt_spellings()
- .area()
- .borders()
- .calling_codes()
- .capital()
- .capital_latlng()
- .currencies()
- .demonym()
- .geojson()`
- .iso()
- .languages()
- .latlng()
- .native_name()
- .population()
- .region()
- .subregion()
- .timezones()
- .tld()
- .translations()
- .wiki()
- .google()
- .all()
pip install countryinfo
OR, git clone
git clone https://github.com/porimol/countryinfo.git
cd countryinfo
python setup.py install
To access one of the country properties available, you'll need to use one of the API methods listed below and pass a country in either way.
Returns all available information for a specified country.
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.info()
# returns object,
{
'ISO': {
'alpha2': 'SG',
'alpha3': 'SGP'
},
'altSpellings': [
'SG',
'Singapura',
'Republik Singapura',
'新加坡共和国'
],
'area': 710,
'borders': [],
'callingCodes': ['65'],
'capital': 'Singapore',
'capital_latlng': [
1.357107,
103.819499
],
'currencies': ['SGD'],
'demonym': 'Singaporean',
'flag': '',
'geoJSON': {},
'languages': [
'en',
'ms',
'ta',
'zh'
],
'latlng': [
1.36666666,
103.8
],
'name': 'Singapore',
'nativeName': 'Singapore',
'population': 5469700,
'provinces': ['Singapore'],
'region': 'Asia',
'subregion': 'South-Eastern Asia',
'timezones': ['UTC+08:00'],
'tld': ['.sg'],
'translations': {
'de': 'Singapur',
'es': 'Singapur',
'fr': 'Singapour',
'it': 'Singapore',
'ja': 'シンガポール'
},
'wiki': 'http://en.wikipedia.org/wiki/singapore',
'google': 'https://www.google.com/search?q=Singapore'
}
# Similar can also be achieved via country code or any
# alternate name of a country. For example, Singapur
# would be:
country = CountryInfo('SG')
Return provinces list
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.provinces()
# returns object,
['Singapore']
Returns alternate spellings for the name of a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.alt_spellings()
# returns list of strings, alternate names
# ['SG', 'Singapura', 'Republik Singapura', '新加坡共和国']
Returns area (km²) for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.area()
# returns number of square kilometer area
710
Returns bordering countries (ISO3) for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.borders()
# returns array of strings, ISO3 codes of countries that border the given country
[]
Returns international calling codes for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.calling_codes()
# returns array of calling code strings
['65']
Returns capital city for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.capital()
# returns string
'Singapore'
Returns capital city latitude and longitude for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.capital_latlng()
# returns array, approx latitude and longitude for country capital
[1.357107, 103.819499]
Returns official currencies for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.currencies()
# returns array of strings, currencies
# ['SGD']
Returns the demonyms for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.demonym()
# returns string, name of residents
'Singaporean'
Returns geoJSON for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Bangladesh')
country.geo_json()
# returns object of GeoJSON data
{
'features': [
{
'geometry': {
'coordinates': [[[92.672721, 22.041239],
[92.652257, 21.324048],
[92.303234, 21.475485],
[92.368554, 20.670883],
[92.082886, 21.192195],
[92.025215, 21.70157],
[91.834891, 22.182936],
[91.417087, 22.765019],
[90.496006, 22.805017],
[90.586957, 22.392794],
[90.272971, 21.836368],
[89.847467, 22.039146],
[89.70205, 21.857116],
[89.418863, 21.966179],
[89.031961, 22.055708],
[88.876312, 22.879146],
[88.52977, 23.631142],
[88.69994, 24.233715],
[88.084422, 24.501657],
[88.306373, 24.866079],
[88.931554, 25.238692],
[88.209789, 25.768066],
[88.563049, 26.446526],
[89.355094, 26.014407],
[89.832481, 25.965082],
[89.920693, 25.26975],
[90.872211, 25.132601],
[91.799596, 25.147432],
[92.376202, 24.976693],
[91.915093, 24.130414],
[91.46773, 24.072639],
[91.158963, 23.503527],
[91.706475, 22.985264],
[91.869928, 23.624346],
[92.146035, 23.627499],
[92.672721, 22.041239]]],
'type': 'Polygon'
},
'id': 'BGD',
'properties': {'name': 'Bangladesh'},
'type': 'Feature'}],
'type': 'FeatureCollection'
}
Returns ISO codes for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.iso()
# returns object of ISO codes
{'alpha2': 'SG', 'alpha3': 'SGP'}
country.iso(2)
# returns object of ISO codes
'SG'
country.iso(3)
# returns object of ISO codes
'SGP'
Returns official languages for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.languages()
# returns array of language codes
['en', 'ms', 'ta', 'zh']
Returns approx latitude and longitude for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.latlng()
# returns array, approx latitude and longitude for country
[1.36666666, 103.8]
Returns the name of the country in its native tongue
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.native_name()
# returns string, name of country in native language
'Singapore'
Returns approximate population for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.population()
# returns number, approx population
5469700
Returns general region for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.region()
# returns string
'Asia'
Returns a more specific region for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.subregion()
# returns string
'South-Eastern Asia'
Returns all timezones for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.timezones()
# returns array of timezones
['UTC+08:00']
Returns official top level domains for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.tld()
# returns array of top level domains specific to the country
['.sg']
Returns translations for a specified country name in popular languages
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.translations()
# returns object of translations of country name in major languages
{
'de': 'Singapur',
'es': 'Singapur',
'fr': 'Singapour',
'it': 'Singapore',
'ja': 'シンガポール'
}
Returns link to wikipedia page for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.wiki()
# returns string URL of wikipedia article on country
'http://en.wikipedia.org/wiki/singapore'
Returns link to google page for a specified country
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Singapore')
country.google()
# returns string URL of google page on country
'https://www.google.com/search?q=Singapore'