Epidata API Clients
To access Delphi Epidata programmatically, we recommend our client libraries:
- R: epidatr,
- Python: epidatpy (recommended) and delphi-epidata,
- Javascript: delphi-epidata.
For anyone looking for COVIDCast data, please visit our COVIDCast API Client Libraries.
The following samples show how to import the library and fetch Delphi’s
COVID-19 Surveillance Streams from Facebook Survey CLI for county 06001 and days
20200401
and 20200405-20200414
(11 days total).
R
Install epidatr
from CRAN
with install.packages("epidatr")
.
# Configure API key interactively, if needed. See
# https://cmu-delphi.github.io/epidatr/articles/epidatr.html#api-keys for details.
#save_api_key()
library(epidatr)
data <- pub_covidcast('fb-survey', 'smoothed_cli', 'county', 'day', geo_values = '06001',
time_values = c(20200401, 20200405:20200414))
cat(data)
Python
The epidatpy
package will soon be available on PyPI as epidatpy
.
Meanwhile, it can be installed from GitHub with
pip install "git+https://github.com/cmu-delphi/epidatpy.git#egg=epidatpy"
.
# Configure API key, if needed.
# https://github.com/cmu-delphi/epidatpy/blob/dev/docs/index.rst#api-keys
from epidatpy import EpiDataContext, EpiRange
# Create the client object.
epidata = EpiDataContext()
apicall = epidata.pub_covidcast(
data_source="jhu-csse",
signals="confirmed_cumulative_num",
geo_type="nation",
time_type="day",
geo_values="us",
time_values=EpiRange(20210405, 20210410),
)
print(apicall.df())
Install delphi-epidata
from PyPI with
pip install delphi-epidata
.
from delphi_epidata import Epidata
# Configure API key, if needed.
#Epidata.auth = ('epidata', <your API key>)
res = Epidata.covidcast('fb-survey', 'smoothed_cli', 'day', 'county', [20200401, Epidata.range(20200405, 20200414)], '06001')
print(res['result'], res['message'], len(res['epidata']))
JavaScript (in a web browser)
The minimalist JavaScript client does not currently support API keys. If you need API key support in JavaScript, contact delphi-support+privacy@andrew.cmu.edu.
<script src="delphi_epidata.js"></script>
<script>
EpidataAsync.covidcast(
"fb-survey",
"smoothed_cli",
"day",
"county",
[20200401, EpidataAsync.range(20200405, 20200414)],
"06001"
).then((res) => {
console.log(
res.result,
res.message,
res.epidata != null ? res.epidata.length : 0
);
});
</script>
R (legacy)
The old Delphi Epidata R client is available here, but its use is discouraged.
# Configure API key, if needed.
#option('epidata.auth', <your API key>)
source('delphi_epidata.R')
res <- Epidata$covidcast('fb-survey', 'smoothed_cli', 'day', 'county', list(20200401, Epidata$range(20200405, 20200414)), '06001')
cat(paste(res$result, res$message, length(res$epidata), "\n"))