🚀 Socket Launch Week 🚀 Day 4: Introducing Historical Analytics.Learn More
Socket
Sign inDemoInstall
Socket

python-restcountries

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

python-restcountries

Python API Wrapper for restcountries.com

2.0.0
PyPI
Maintainers
1

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

Keywords

api

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts