A new Python library which tells the COVID-19 related information (country-wise) and it show that how many cases of confirmed, active, deaths, recovered found in that particular Country.
Requirement:
You have python package named COVID and python >= 3.6
Installation:
pip install covid
Dependencies:
- pydantic
- requests
Example:
from covid import Covid covid = Covid() india = covid.get_status_by_country_name("india") data ={ key:india[key] for key in india.keys() and {'confirmed', 'active', 'deaths', 'recovered'} } print(data) |
Output:
{‘confirmed’: 119419, ‘active’: 66863, ‘recovered’: 48957, ‘deaths’: 3599}
Let’s look at the modules basic functionality –
- List Countries and their Id’s: This comes in need when you need to know the names of countries while using get_status_by_country_name, eg to use ‘America’ or ‘United States of America’ or ‘US’
fromcovidimportCovidcovid=Covid()countries=covid.list_countries()print(countries)chevron_rightfilter_noneOutput:
[{‘id’: ’18’, ‘name’: ‘US’}, {‘id’: ’14’, ‘name’: ‘Russia’}, {‘id’: ’22’, ‘name’: ‘Brazil’}, {‘id’: ’17’, ‘name’: ‘United Kingdom’}, {‘id’: ’19’, ‘name’: ‘Spain’}, {‘id’: ’11’, ‘name’: ‘Italy’}, {‘id’: ‘7’, ‘name’: ‘France’}, {‘id’: ‘8’, ‘name’: ‘Germany’}, {‘id’: ‘176’, ‘name’: ‘Turkey’}, {‘id’: ’93’, ‘name’: ‘Iran’}, {‘id’: ’91’, ‘name’: ‘India’}, {‘id’: ‘141’, ‘name’: ‘Peru’}, {‘id’: ‘4’, ‘name’: ‘China’}, {‘id’: ‘3’, ‘name’: ‘Canada’}, {‘id’: ‘153’, ‘name’: ‘Saudi Arabia’}, {‘id’: ’20’, ‘name’: ‘Mexico’},
Note: The list is too long, the above output is just a part of the list.
- Get Data: To get COVID-19 related information.
fromcovidimportCovidcovid=Covid()print(covid.get_data())chevron_rightfilter_noneOutput:
[{‘id’: ’18’, ‘country’: ‘US’, ‘confirmed’: 1577758, ‘active’: 1181132, ‘deaths’: 94729, ‘recovered’: 298418, ‘latitude’: 40.0, ‘longitude’: -100.0, ‘last_update’: 1590143562000}, {‘id’: ’14’, ‘country’: ‘Russia’, ‘confirmed’: 326448, ‘active’: 223374, ‘deaths’: 3249, ‘recovered’: 99825, ‘latitude’: 61.524, ‘longitude’: 105.3188, ‘last_update’: 1590143562000},
Note: The list is too long, the above output is just a part of the list.
- Get Status By Country ID: To get COVID-19 related information by Country Id
fromcovidimportCovidcovid=Covid()cases=covid.get_status_by_country_id(18)print(cases)chevron_rightfilter_noneOutput:
{‘id’: ’18’, ‘country’: ‘US’, ‘confirmed’: 1541110, ‘active’: 1154535, ‘deaths’: 92712, ‘recovered’: 289392, ‘latitude’: 40.0, ‘longitude’: -100.0, ‘last_update’: 1590003166000}
- Get Status By Country Name
fromcovidimportCovidcovid=Covid()italy_cases=covid.get_status_by_country_name("italy")print(italy_cases)chevron_rightfilter_noneOutput:
{‘id’: ’11’, ‘country’: ‘Italy’, ‘confirmed’: 227364, ‘active’: 62752, ‘deaths’: 32330, ‘recovered’: 132282, ‘latitude’: 41.8719, ‘longitude’: 12.5674, ‘last_update’: 1590003166000}
- Get Total Confirmed cases, Active cases, Recovered cases and Deaths
fromcovidimportCovidcovid=Covid()confirmed=covid.get_total_confirmed_cases()print('Confirmed :', end=" ")print(confirmed)active=covid.get_total_active_cases()print("Active:", end=" ")print(active)recovered=covid.get_total_recovered()print('Recovered:', end=" ")print(recovered)deaths=covid.get_total_deaths()print('Deaths:', end=" ")print(deaths)chevron_rightfilter_noneOutput:
Confirmed : 4955312 Active: 2750033 Recovered: 1874998 Deaths: 325810
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.
Recommended Posts:
- COVID-19 Data Visualization using matplotlib in Python
- Scraping COVID-19 statistics using Python and Selenium
- Python - Retrieve latest Covid-19 World Data using COVID19Py library
- Python - Get Hardware and System information using platform module
- COVID-19 Peak Prediction using Logistic Function
- Scraping Covid-19 statistics using BeautifulSoup
- Detecting Covid-19 with Chest X-ray
- Python | Update a list of tuples using another list
- How to update data in a Collection using Python?
- Python MariaDB - Update Query using PyMySQL
- Update all Documents in a Collection using PyMongo
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- MongoDB Python | Insert and Update Data
- Python Set | update()
- Python Dictionary | update() method
- Python | Pandas Series.update()
- Python | Update each element in tuple list
- Python: Update Nested Dictionary
- Python | Even values update in dictionary
- Python MySQL - Update Query
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.

