Python – Retrieve latest Covid-19 World Data using COVID19Py library

COVID19Py Library retrieves the latest data revolving around the Covid-19 pandemic. This Covid-19 World Dataset is hosted at the John Hopkins University servers. 

To install the library, execute below command in your system command line:

pip install COVID19Py 

The library provides the following methods:

  • getAll(): Retrieve the entire dataset as a JSON
  • getLatest(): Get the latest stats of confirmed cases, recoveries and deaths
  • getLocations(): Get the locations where Covid-19 cases exist
  • getLatestChanges(): Look for any changes since you last retrieved the data

Below example illustrate the above methods:

Example:



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import given package
import COVID19Py
  
# Create an object,
# specify data source as JHU Servers
covid = COVID19Py.COVID19(data_source = "jhu")
  
# Retrieve all Data
# in the form of json
data = covid.getAll()
  
# Enormous Data will be returned
print("Data", data) 
  
# Get the latest data
latest = covid.getLatest()
print("Latest Data", latest)
  
# Get Locations where covid cases exist
# Can be Ranked by 'confirmed' cases,
# number of 'deaths' or
# number of 'recovered' patients
locations = covid.getLocations(timelines = True,
                               rank_by = 'confirmed')
print("Locations", locations) 
  
# Check for any changes since
# data was last retrieved
changes = covid.getLatestChanges()
  
# Printing changes, if any
print("Changes since last visit", changes)

chevron_right


Output:

Data: Enormous data returned in the json form; this screenshot represents just the first few lines of the data.

Country-wise Covid Data in the Json form

Country-wise Covid Data in the form of nested dictionaries

Latest Data: Latest numbers related to Covid19 (Globally)

Global Covid19 Numbers

Global Covid19 Numbers

Location Data: Enormous location-wise Covid Data will be return in json form.This screenshot represents the first few lines.

Location Data

Location Data

Changes since Last Visit: Currently all 0.

Changes since last visit

Changes since last visit


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.