Skip to main content

python-restcountries


Code style: black Coverage Status PyPI version

This is a simple python wrapper for the API of http://restcountries.com. If there are any issues, please use this repository to contact me about it.

Installation

pip install python-restcountries

Usage

Just import the API Wrapper and start using it!::

# v1 from restcountries import RestCountryApi as rapi
from restcountries import RestCountryApiV2 as rapi

def foo(name):
    country_list = rapi.get_countries_by_name('France')

Response filtering

Pass filters as a keyword argument to any of RestCountryApiV2 or RestCountryApi methods, this filters the response returned by the api. Thus the Country Object will only contain the attributes in the filters list.

# v1 from restcountries import RestCountryApi as rapi
from restcountries import RestCountryApiV2 as rapi

def foo(name):
    country_list = rapi.get_countries_by_name("France" ,filters=["name","currencies","capital"])

Attributes that can be passed in the filters list.

  • topLevelDomain
  • alpha2Code
  • alpha3Code
  • currencies
  • capital
  • callingCodes
  • altSpellings
  • relevance
  • region
  • subregion
  • translations
  • population
  • latlng
  • demonym
  • area
  • gini
  • timezones
  • borders
  • nativeName
  • name
  • numericCode
  • languages
  • flag
  • regionalBlocs
  • cioc

The Country object

The API returns Country objects or a list of Country objects. Through the country objects one is able to access following attributes.

country = country_list[0]
print(country.name)
France
  • top_level_domain
  • alpha2_code
  • alpha3_code
  • currencies
  • capital
  • calling_codes
  • alt_spellings
  • relevance
  • region
  • subregion
  • translations
  • population
  • latlng
  • demonym
  • area
  • gini
  • timezones
  • borders
  • native_name
  • name
  • numeric_code
  • languages
  • flag
  • regional_blocs
  • cioc

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-restcountries-2.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_restcountries-2.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file python-restcountries-2.0.0.tar.gz.

File metadata

  • Download URL: python-restcountries-2.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for python-restcountries-2.0.0.tar.gz
Algorithm Hash digest
SHA256 17ef11e7a67f7ee1649bc901ce87cb495f0e3a4d102daaef47cb620ecc545143
MD5 4dd9127f78159226f9e993cf4493032d
BLAKE2b-256 96e8fffe03db10b01fe3861678f9414db8811819551b707947448825fbf507c0

See more details on using hashes here.

File details

Details for the file python_restcountries-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_restcountries-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for python_restcountries-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f92a7669962bdcb610f0bd500611f144a185ddc0556292167bb32327984fced9
MD5 c3f306514af1d978190b1d34e4a72665
BLAKE2b-256 0efdc231f398988cedd32d8ec42a1f23dc4f25fb4623a9c74c538c27789388dd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.0

2 files

0.3

2 files

0.2

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page