Package: disease.py
disease.pyThe official Python wrapper for theOpen Disease API. Formerlycorona-api.RequirementsPython 3.5 or aboveaiohttp (python3 -m pip install -U aiohttp)InstallationUsing pip (recommended)python3 -m pip install -U disease.pyImporting is then as easy asimport diseaseapi.SupportGet support for this on Discord, either on ourofficial serveror theDisease.sh server.Basic usageimportdiseaseapiimportasyncioclient=diseaseapi.Client()covid=client.covid19# for influenza, use: influenza = client.influenzaasyncdefmain():data=awaitcovid.all()print(data.cases,data.today.cases,data.deaths,data.today.deaths)awaitclient.request_client.close()asyncio.get_event_loop().run_until_complete(main())Optional parameters in Covid methodsParameterSupported methodsAccepted valuesyesterday-all()-country()-all_countries()-all_states()-state()-all_continents()-continent()-True-Falsetwo_days_ago-all()-country()-all_countries()-continent()-all_continents()-True-Falsesort-all_countries()-all_states()-all_continents()Depends on the endpoint used. Consult the API documentation to see which endpoints support which parameters.allow_none-all()-country()-all_countries()-all_continents()-continent()-state()-all_states()-gov()-True-Falselast_days-country_history()-province_history()-county_history()-vaccine_coverage()-vaccine_countries()-vaccine_country()-'all'- Any int valueExamplesThe following examples cover the basic usage of the library and its various features.
Note; many methods also supportyesterday=True,sort='sort method'andallow_none=Truekwargs to get data from the previous day or sorted by various parameters. Refer to the table above to find out which ones do and do not.Discord botThere is an example cog for your Discord bothere.Basic dataGlobal dataimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_all():data=awaitclient.all()#get global dataprint(data.cases,data.deaths)#print the number of global cases and deathsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_all())Data for a specific countryimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_country():data=awaitclient.country('UK')#get data for the UK today,print(data.cases,data.deaths)#print the number of cases and deaths for the UKawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_country())Data for more than one countryimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_countries():data=awaitclient.country('UK','USA','China')#get data for specified countries#to get data for every country supported, use:  all_countries()print(data)#prints a list of Countryawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_countries())US StatesData for a specific stateimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_state():data=awaitclient.state('Ohio')#get data for Ohio today,print(data.cases,data.deaths)#print the number of cases and deaths for Ohioawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_state())Data for more than one stateimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_states():data=awaitclient.state('Ohio','California','Texas')#get data for specified states#to get data for every state supported, use:  all_states()print(data)#prints a list of Stateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_states())Historical statisticsHistorical data globallyimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_history():data=awaitclient.country_history('all','all')#get all the historical data for the worldprint(data.name,data.history.cases[0].date,data.history.cases[0].value)#print name (in this case 'Global'), the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history())Historical data for a countryimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_history():data=awaitclient.country_history('UK',7)#get the past week of historical data for the UKprint(data.name,data.history.cases[0].date,data.history.cases[0].value)#print name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history())Historical data for a provinceimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_history_province():data=awaitclient.province_history('UK','Gibraltar',7)#get the past week of historical data for Gibraltar, UKprint(data.province,data.history.cases[0].date,data.history.deaths[0].value)#print province name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history_province())Historical data for a county within a US stateimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_county():data=awaitclient.county_history('Ohio','Adams')#get all historical data for Adams, Ohio, USAprint(data.name,data.province,data.history.cases[0].date,data.history.cases[0].value)#print state and county name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_county())John Hopkins University CSSEAll data from the JHU CSSEimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_jhu():data=awaitclient.jhucsse()#get data for every province and country JHU supportsprint(data)#print a long list of JhuCsseawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu())Data for a county within a US stateimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_jhu_county():data=awaitclient.jhu_county('Ohio','Adams')#get data for Adams, Ohioprint(data.province_name,data.county_name,data.confirmed_cases)#print the state, county and case numberawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu_county())Data for every county in the USAimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_jhu_counties():data=awaitclient.jhu_all_counties()print(data)#print a long list of JhuCsseawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu_counties())Continental dataData for every continentimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_conts():data=awaitclient.all_continents()first=data[0]print(first.name,first.cases,first.deaths)#print some info for the first continent in the listawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_conts())Data for a single continentimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_one_cont():data=awaitclient.continent('Europe')print(data.name,data.cases,data.deaths)#print some info for the specified continentawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_cont())New York TimesUSA data from NY Timesimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_nyt_us():data=awaitclient.nyt()first=data[0]print(first.date,first.cases,first.deaths)#print first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_us())All USA state data from NY Timesimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_nyt_states():data=awaitclient.nyt_states()first=data[0]print(first.state,first.date,first.cases)#print some data from the frst elementawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_states())Data for a single state from NY Timesimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_nyt_state():data=awaitclient.nyt_state('Ohio')first=date[0]print(first.date,first.cases,first.deaths)#print the first date, and case/death numberawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_state())Every county from NY Timesimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_counts():data=awaitclient.nyt_counties()first=data[0]print(first.date,first.cases,first.deaths)#print part of the first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_counts())Counties from NYT filtered by nameimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_one_county():data=awaitclient.nyt_county('Adams')first=data[0]print(first.date,first.cases,first.deaths)#print part of the first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_county())Apple MobilityEvery country supported by Apple Mobility Dataimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefall_apples():data=awaitclient.apple_countries()print(data)#print all supported countriesawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(apples())Every subregion within a country for Apple Mobilityimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_subregions():data=awaitclient.apple_subregions('UK')print(data.subregions)#print all supported subregions within the countryawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_subregions())Apple's Mobility data for a subregionimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_one_sub():data=awaitclient.apple_mobility_data('UK','London')first=data.statistics[0]print(first.date,first.name,first.driving)#print some data about the first resultawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_sub())Governmental dataAll countries supported by the API for government dataimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_gov_countries():data=awaitclient.gov_countries()print(data)#print the supported countriesawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_gov_countries())Get the data from a country's government siteimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefget_country_gov():data=awaitclient.gov('UK')print(data)#probably will return a large amount of dict data.awaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_country_gov())Get the vaccine data globallyimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefvax_cov():data=awaitclient.vaccine_coverage(30)print(data[0].date.day,data[0].value)#global vaccine data 30 days agoawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(vax_cov())Get the vaccine data for all countriesimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefvax_all():data=awaitclient.vaccine_countries(30)d=data[0]print(d.country,d.timeline[0].date,d.timeline[0].value)awaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(vax_all())Get the vaccine data for a specific countryimportdiseaseapiimportasyncioclient=diseaseapi.Client().covid19asyncdefvax_ctry():data=awaitclient.vaccine_country('UK',30)print(d.country,d.timeline[0].date,d.timeline[0].value)awaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(vac_ctry())NoteDue to the fact that each country's governmental/official statistics website is different (layouts, tables etc.), it is not feasible to create a standardised class for the data. However, the data returned will be in standard JSON format so it should be relatively simple to work with.