Google Flu Trends

Attribute Details
Source Name gft
Data Source Google Flu Trends Estimates (context)
Geographic Levels National, HHS regions, US states (see US Regions and States), and select cities (see Selected US Cities)
Temporal Granularity Weekly (Epiweek)
Reporting Cadence Inactive - No longer updated since 2015w32
Temporal Scope Start 2003w40
License Google Terms of Service

Overview

This data source provides influenza activity estimates from Google Flu Trends, which used search query data to track ILI activity.

General topics not specific to any particular endpoint are discussed in the API overview. Such topics include: contributing, citing, and data licensing.

Table of contents

  1. The API
    1. Parameters
      1. Required
    2. Response
  2. Example URLs
    1. Google Flu Trends on 2015w01 (national)
  3. Code Samples
    1. Legacy Clients

The API

The base URL is: https://api.delphi.cmu.edu/epidata/gft/

Parameters

Required

Parameter Description Type
locations Locations to fetch. National, HHS regions, US states (see US Regions and States), and select cities (see Selected US Cities). list of strings
epiweeks Epiweeks to fetch. Supports [epirange()] and defaults to all (“*”) dates. list of epiweeks

Response

Field Description Type
result result code: 1 = success, 2 = too many results, -2 = no results integer
epidata list of results array of objects
epidata[].location location string
epidata[].epiweek epiweek integer
epidata[].num GFT estimate integer
message success or error message string

Example URLs

https://api.delphi.cmu.edu/epidata/gft/?locations=nat&epiweeks=201501

{
  "result": 1,
  "epidata": [
    {
      "location": "nat",
      "epiweek": 201501,
      "num": 4647
    }
  ],
  "message": "success"
}

Code Samples

Libraries are available for R and Python. The following samples show how to import the library and fetch Google Flu Trends data for epiweeks 201501-201510.

Install the package using pip:

pip install -e "git+https://github.com/cmu-delphi/epidatpy.git#egg=epidatpy"
# Import
from epidatpy import CovidcastEpidata, EpiDataContext, EpiRange
# Fetch data
epidata = EpiDataContext()
res = epidata.pub_gft(locations='nat', epiweeks=EpiRange(201501, 201510))
print(res)
library(epidatr)
# Fetch data
res <- pub_gft(locations = 'nat', epiweeks = epirange(201501, 201510))
print(res)

Legacy Clients

We recommend using the modern client libraries mentioned above. Legacy clients are also available for Python, R, and JavaScript.

Optionally install the package using pip(env):

pip install delphi-epidata

Otherwise, place delphi_epidata.py from this repo next to your python script.

# Import
from delphi_epidata import Epidata
# Fetch data
res = Epidata.gft(['nat'], Epidata.range(201501, 201510))
print(res['result'], res['message'], len(res['epidata']))

Place delphi_epidata.R from this repo next to your R script.

source("delphi_epidata.R")
# Fetch data
res <- Epidata$gft(locations = list("nat"), epiweeks = Epidata$range(201501, 201510))
print(res$message)
print(length(res$epidata))
<!-- Imports -->
<script src="delphi_epidata.js"></script>
<!-- Fetch data -->
<script>
  EpidataAsync.gft('nat', EpidataAsync.range(201501, 201510)).then((res) => {
    console.log(res.result, res.message, res.epidata != null ? res.epidata.length : 0);
  });
</script>