A python module for returning data about countries, ISO info and states/provinces within them.
- .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'
Returns array of objects containing all available data for all countries. This will be super big. Not recommended.
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo()
country.all()
# returns array of objects,
{
'zimbabwe': {'ISO': {'alpha2': 'ZW', 'alpha3': 'ZWE'},
'altSpellings': ['ZW', 'Republic of Zimbabwe'],
'area': 390757,
'borders': ['BWA', 'MOZ', 'ZAF', 'ZMB'],
'callingCodes': ['263'],
'capital': 'Harare',
'capital_latlng': [-17.831773, 31.045686],
'currencies': ['USD'],
'demonym': 'Zimbabwean',
'flag': '',
'geoJSON': {'features': [{'geometry': {'coordinates': [[[31.191409,
-22.25151],
[30.659865,
-22.151567],
[30.322883,
-22.271612],
[29.839037,
-22.102216],
[29.432188,
-22.091313],
[28.794656,
-21.639454],
[28.02137,
-21.485975],
[27.727228,
-20.851802],
[27.724747,
-20.499059],
[27.296505,
-20.39152],
[26.164791,
-19.293086],
[25.850391,
-18.714413],
[25.649163,
-18.536026],
[25.264226,
-17.73654],
[26.381935,
-17.846042],
[26.706773,
-17.961229],
[27.044427,
-17.938026],
[27.598243,
-17.290831],
[28.467906,
-16.4684],
[28.825869,
-16.389749],
[28.947463,
-16.043051],
[29.516834,
-15.644678],
[30.274256,
-15.507787],
[30.338955,
-15.880839],
[31.173064,
-15.860944],
[31.636498,
-16.07199],
[31.852041,
-16.319417],
[32.328239,
-16.392074],
[32.847639,
-16.713398],
[32.849861,
-17.979057],
[32.654886,
-18.67209],
[32.611994,
-19.419383],
[32.772708,
-19.715592],
[32.659743,
-20.30429],
[32.508693,
-20.395292],
[32.244988,
-21.116489],
[31.191409,
-22.25151]]],
'type': 'Polygon'},
'id': 'ZWE',
'properties': {'name': 'Zimbabwe'},
'type': 'Feature'}],
'type': 'FeatureCollection'},
'languages': ['en', 'sn', 'nd'],
'latlng': [-20, 30],
'name': 'Zimbabwe',
'nativeName': 'Zimbabwe',
'population': 13061239,
'provinces': ['Bulawayo',
'Harare',
'ManicalandMashonaland Central',
'Mashonaland East',
'Mashonaland'],
'region': 'Africa',
'subregion': 'Eastern Africa',
'timezones': ['UTC+02:00'],
'tld': ['.zw'],
'translations': {'de': 'Simbabwe',
'es': 'Zimbabue',
'fr': 'Zimbabwe',
'it': 'Zimbabwe',
'ja': 'ジンバブエ'},
'wiki': 'http://en.wikipedia.org/wiki/zimbabwe',
'google': 'https://www.google.com/search?q=Zimbabwe'}
}
Special thanks to johan for his work on johan/world.geo.json, who made the geojson portion of this build possible.
Repo: countryjs
Maintainer: Oz Haven
See the list of contributors who participated in this project.
If you want to contribute to countryinfo
and make it better, your help is very welcome.
You can make constructive, helpful bug reports, feature requests and the noblest of all contributions.
If like to contribute in a good way, then follow the following guidelines.
- Create a personal fork on Github.
- Clone the fork on your local machine.(Your remote repo on Github is called
origin
.) - Add the original repository as a remote called
upstream
. - If you created your fork a while ago be sure to pull upstream changes into your local repository.
- Create a new branch to work on! Branch from
dev
. - Implement/fix your feature, comment your code.
- Follow
countryinfo
's code style, including indentation(4 spaces). - Write or adapt tests as needed.
- Add or change the documentation as needed.
- Push your branch to your fork on Github, the remote
origin
. - From your fork open a pull request to the
dev
branch. - Once the pull request is approved and merged, please pull the changes from
upstream
to your local repo and delete your extra branch(es).
This is being maintained in the contributor's free time, and as such, may contain minor errors in regards to some countries. Most of the information included in this library is what is listed on Wikipedia. If there is an error, please let me know and I will do my best to correct it.
Copyright (c) 2018, Porimol Chandro [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.