Home

Awesome

<div align="center"><img width=250 height=250 src="https://raw.githubusercontent.com/Spiderpig86/coronavirus-us-api/master/static/coronavirus-us-1024.png" /></div> <h1 align="center">coronavirus-us-api</h1> <div align="center">

forthebadge

<br />

CI MIT License codecov Code style: black Reviewed by Hound

</div>

What

This API is designed to serve up to date information on confirmed cases and deaths across the United States at a country, state, and county level.

Built With

Documentation

Since coronavirus-us-api is powered by FastAPI, the API specification strictly follows the OpenAPI standard. The JSON file for this API can be found here.

The API documentation comes in three flavors:

Data Sources

The data used by the API comes from two sources:

Endpoints

Before getting started, let's go over some of the common types you will see in the remainder of the documentation:

Timelines

KeyDescriptionType
timelinesObject containing measured statistics and their historical values.Object
timelines.statisticObject that contains information for that statistic. For now, only confirmed and deaths are supported.Object
timelines.statistic.historyObject containing a list of key value pairs where the key is the date and the value is the number for that statistic for that date.Object
timelines.statistic.latestValue of statistic at current date.Object

Properties

KeyDescriptionType
propertiesObject containing information regarding naming, classification, coordinates, and population.Object
propertes.uidUnique ID used by JHU CSSE to identify different locations.string
properties.iso2Country code following alpha-2 ISO country name standards.string
properties.iso3Country code following alpha-3 ISO country name standards.string
properties.code3A three digit numerical country code identifier.string
properties.fipsA five digit identifier for US county and county-equivalents.string
properties.countyName of US county if applicable.string
properties.stateName of US state if applicable.string
properties.countryCode for country.string
properties.coordinatesObject containing coordinates for given location.object
properties.coordinates.latitudeLatitude of location.string
properties.coordinates.longitudeLongitude of location.string
properties.combined_keyUnique key combining location names based on specificity of request result.string
properties.populationPopulation of location.number

Location Data

Endpoints for fetching information (confirmed, deaths, etc) at the country, state, or county level. By default, these endpoints will show the latest statistic. Other fields such as the timeline and properties for the location can be enabled via query parameters.

Country

Retrieve information on the country level.

GET /api/country/all

Query Parameters

ParameterDescriptionType
sourceThe data source to fetch data from.<br>Options: ["nyt", "jhu"]<br>Default: "nyt"string
timelinesDisplay timeline for daily statistics.<br>Default: falseboolean
propertiesDisplay properties associated with a given location.<br>Default: falseboolean

Sample Request

GET /api/country/all?timelines=true&properties=true
<details> <summary><b>Sample Response</b></summary>
{
  "latest": {
    "confirmed": 3199715,
    "deaths": 133901
  },
  "locations": [
    {
      "id": "US",
      "country": "US",
      "state": "",
      "county": "",
      "fips": "",
      "timelines": {
        "confirmed": {
          "history": {
            "2020-01-21": 1,
            "2020-01-22": 1,
            "2020-01-23": 1,
            ... 
          },
          "latest": 3199715
        },
        "deaths": {
          "history": {
            "2020-01-21": 0,
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          },
          "latest": 133901
        }
      },
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 3199715,
        "deaths": 133901
      },
      "properties": {
        "uid": "840",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "",
        "county": "",
        "state": "",
        "country": "US",
        "coordinates": {
          "latitude": "37.0902",
          "longitude": "-95.7129"
        },
        "combined_key": "United States",
        "population": 329466283
      }
    }
  ]
}
</details>

Response

KeyDescriptionType
latestObject containing latest measurements for supported statistics.object
latest.statisticContains the value for statistic at current date.number
locationsList of Location matching given criteria if present.List<Location>
locations.location.idUnique ID for the country.string
locations.location.countryName of the country.string
locations.location.stateState of the location if applicable.string
locations.location.countyCounty of the location if applicable.string
locations.location.fipsFips code of location if applicable.string
locations.location.timelinesTimeline for statistics in location.Timeline
locations.location.last_updatedDate for when the data was updated.string
locations.location.latestLatest values for supported statistics.string
locations.location.propertiesProperties for a given location.Properties

State

Retrieve information on the state level.

GET /api/state/all

Query Parameters

ParameterDescriptionType
sourceThe data source to fetch data from.<br>Options: ["nyt", "jhu"]<br>Default: "nyt"string
timelinesDisplay timeline for daily statistics.<br>Default: falseboolean
propertiesDisplay properties associated with a given location.<br>Default: falseboolean
fipsOnly show locations matching the fips code.number
stateOnly show locations matching state name. The name can be the full name or a 2-letter ANSI code.string

Sample Request

GET /api/state/all?timelines=true&properties=true
<details> <summary><b>Sample Response</b></summary>
{
  "latest": {
    "confirmed": 3199790,
    "deaths": 133906
  },
  "locations": [
    {
      "id": "US@Washington@53",
      "country": "US",
      "state": "Washington",
      "county": "",
      "fips": "53",
      "timelines": {
        "confirmed": {
          "history": {
            "2020-01-21": 1,
            "2020-01-22": 1,
            "2020-01-23": 1,
            ...
          },
          "latest": 41090
        },
        "deaths": {
          "history": {
            "2020-01-21": 0,
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          },
          "latest": 1426
        }
      },
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 41090,
        "deaths": 1426
      },
      "properties": {
        "uid": "84000053",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "53",
        "county": "",
        "state": "Washington",
        "country": "US",
        "coordinates": {
          "latitude": "47.4009",
          "longitude": "-121.4905"
        },
        "combined_key": "Washington, US",
        "population": 7614893
      }
    }
  ]
}
</details>

Response

KeyDescriptionType
latestObject containing latest measurements for supported statistics.object
latest.statisticContains the value for statistic at current date.number
locationsList of Location matching given criteria if present.List<Location>
locations.location.idUnique ID for the country.string
locations.location.countryName of the country.string
locations.location.stateState of the location if applicable.string
locations.location.countyCounty of the location if applicable.string
locations.location.fipsFips code of location if applicable.string
locations.location.uid(Optional depends on source) Unique identifier for location.string
locations.location.iso2(Optional depends on source) Country code following alpha-2 ISO country name standards.string
locations.location.iso3(Optional depends on source) Country code following alpha-3 ISO country name standards.string
locations.location.code3(Optional depends on source) A three digit numerical country code identifier.string
locations.location.latitude(Optional depends on source) Latitude of locationstring
locations.location.longitude(Optional depends on source) Longitude of location.string
locations.location.timelinesTimeline for statistics in location.Timeline
locations.location.last_updatedDate for when the data was updated.string
locations.location.latestLatest values for supported statistics.string
locations.location.propertiesProperties for a given location.Properties

Sample Request with Parameter

GET /api/state/all?state=WA
{
  "latest": {
    "confirmed": 39218,
    "deaths": 1424
  },
  "locations": [
    {
      "id": "US@Washington",
      "country": "US",
      "state": "Washington",
      "county": "",
      "fips": "53",
      "uid": "84000053",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "latitude": "47.4009",
      "longitude": "-121.4905",
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 39218,
        "deaths": 1424
      }
    }
  ]
}

County

Retrieve information on the county level.

GET /api/county/all

Query Parameters

ParameterDescriptionType
sourceThe data source to fetch data from.<br>Options: ["nyt", "jhu"]<br>Default: "nyt"string
timelinesDisplay timeline for daily statistics.<br>Default: falseboolean
propertiesDisplay properties associated with a given location.<br>Default: falseboolean
fipsOnly show locations matching the fips code.number
stateOnly show locations matching state name. The name can be the full name or a 2-letter ANSI code.string
countyOnly show locations matching county name.string

Sample Request

GET /api/county/all?source=jhu&timelines=true&properties=true
<details> <summary><b>Sample Response</b></summary>
{
  "latest": {
    "confirmed": 11568,
    "deaths": 633
  },
  "locations": [
    {
      "id": "US@Texas@King",
      "country": "US",
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 0,
        "deaths": 0
      },
      "timelines": {
        "confirmed": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        },
        "deaths": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        }
      },
      "properties": {
        "uid": "84048269",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "48269",
        "county": "King",
        "state": "Texas",
        "country": "US",
        "coordinates": {
          "latitude": "33.61643847",
          "longitude": "-100.2558057"
        },
        "combined_key": "King, Texas, US",
        "population": 272
      },
      "uid": "84048269",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "state": "Texas",
      "county": "King",
      "fips": "48269.0",
      "latitude": "33.61643847",
      "longitude": "-100.2558057"
    },
    {
      "id": "US@Washington@King",
      "country": "US",
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 11568,
        "deaths": 633
      },
      "timelines": {
        "confirmed": {
          "latest": 11568,
          "history": {
            "2020-01-22": 1,
            "2020-01-23": 1,
            ...
          }
        },
        "deaths": {
          "latest": 633,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        }
      },
      "properties": {
        "uid": "84053033",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "53033",
        "county": "King",
        "state": "Washington",
        "country": "US",
        "coordinates": {
          "latitude": "47.49137892",
          "longitude": "-121.8346131"
        },
        "combined_key": "King, Washington, US",
        "population": 2252782
      },
      "uid": "84053033",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "state": "Washington",
      "county": "King",
      "fips": "53033.0",
      "latitude": "47.49137892",
      "longitude": "-121.8346131"
    },
    ...
  ]
}
</details>

Response

KeyDescriptionType
latestObject containing latest measurements for supported statistics.object
latest.statisticContains the value for statistic at current date.number
locationsList of Location matching given criteria if present.List<Location>
locations.location.idUnique ID for the country.string
locations.location.countryName of the country.string
locations.location.stateState of the location if applicable.string
locations.location.countyCounty of the location if applicable.string
locations.location.fipsFips code of location if applicable.string
locations.location.uid(Optional depends on source) Unique identifier for location.string
locations.location.iso2(Optional depends on source) Country code following alpha-2 ISO country name standards.string
locations.location.iso3(Optional depends on source) Country code following alpha-3 ISO country name standards.string
locations.location.code3(Optional depends on source) A three digit numerical country code identifier.string
locations.location.latitude(Optional depends on source) Latitude of locationstring
locations.location.longitude(Optional depends on source) Longitude of location.string
locations.location.timelinesTimeline for statistics in location.Timeline
locations.location.last_updatedDate for when the data was updated.string
locations.location.latestLatest values for supported statistics.string
locations.location.propertiesProperties for a given location.Properties

Sample Request with Parameter

GET /api/state/all?source=jhu&county=King
  "latest": {
    "confirmed": 0,
    "deaths": 0
  },
  "locations": [
    {
      "id": "US@New York@Queens",
      "country": "US",
      "last_updated": "2020-07-12",
      "latest": {
        "confirmed": 0,
        "deaths": 0
      },
      "timelines": {
        "confirmed": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        },
        "deaths": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        }
      },
      "uid": "84036081",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "state": "New York",
      "county": "Queens",
      "fips": "36081.0",
      "latitude": "40.71088124",
      "longitude": "-73.81684712"
    }
  ]
}
GET /api/county/all?source=jhu&county=king&timelines=true&properties=true
{
  "latest": {
    "confirmed": 11568,
    "deaths": 633
  },
  "locations": [
    {
      "id": "US@Texas@King",
      "country": "US",
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 0,
        "deaths": 0
      },
      "timelines": {
        "confirmed": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        },
        "deaths": {
          "latest": 0,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        }
      },
      "properties": {
        "uid": "84048269",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "48269",
        "county": "King",
        "state": "Texas",
        "country": "US",
        "coordinates": {
          "latitude": "33.61643847",
          "longitude": "-100.2558057"
        },
        "combined_key": "King, Texas, US",
        "population": 272
      },
      "uid": "84048269",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "state": "Texas",
      "county": "King",
      "fips": "48269.0",
      "latitude": "33.61643847",
      "longitude": "-100.2558057"
    },
    {
      "id": "US@Washington@King",
      "country": "US",
      "last_updated": "2020-07-11",
      "latest": {
        "confirmed": 11568,
        "deaths": 633
      },
      "timelines": {
        "confirmed": {
          "latest": 11568,
          "history": {
            "2020-01-22": 1,
            "2020-01-23": 1,
            ...
          }
        },
        "deaths": {
          "latest": 633,
          "history": {
            "2020-01-22": 0,
            "2020-01-23": 0,
            ...
          }
        }
      },
      "properties": {
        "uid": "84053033",
        "iso2": "US",
        "iso3": "USA",
        "code3": "840",
        "fips": "53033",
        "county": "King",
        "state": "Washington",
        "country": "US",
        "coordinates": {
          "latitude": "47.49137892",
          "longitude": "-121.8346131"
        },
        "combined_key": "King, Washington, US",
        "population": 2252782
      },
      "uid": "84053033",
      "iso2": "US",
      "iso3": "USA",
      "code3": "840",
      "state": "Washington",
      "county": "King",
      "fips": "53033.0",
      "latitude": "47.49137892",
      "longitude": "-121.8346131"
    },
    ...
  ]
}

Latest

Retrieve the latest statistics for the entire country.

GET /api/country/latest

Query Parameters

ParameterDescriptionType
sourceThe data source to fetch data from.<br>Options: ["nyt", "jhu"]<br>Default: "nyt"string

Sample Request

GET /api/county/latest?source=jhu
<details> <summary><b>Sample Response</b></summary>
{
  "latest": {
    "confirmed": 3184573,
    "deaths": 134092
  },
  "last_updated": "2020-07-12"
}
</details>

Sources

Retrieve the list of sources that the API supports.

GET /api/data/sources

Sample Request

GET /api/data/sources
<details> <summary><b>Sample Response</b></summary>
{
  "sources": [
    "nyt",
    "jhu"
  ]
}
</details>

Heartbeat

Endpoint to test service health.

GET /api/health/heartbeat

Sample Request

GET /api/health/heartbeat
<details> <summary><b>Sample Response</b></summary>
{
  "is_alive": true
}
</details>

Development

Below are some of the dependencies you will need:

Then, clone the repository and create a Pipenv environment.

$ git clone git@github.com:Spiderpig86/coronavirus-us-api.git
$ cd ./coronavirus-us-api

Install Pipenv and set up your virtual environment with the needed dependencies.

$ pip install --user pipenv
$ pipenv sync --dev
$ pipenv shell

Now that this is all setup, you can run the commands to run, test, and format the project. The project will start at localhost:8000 by default (configurable in backend/core/config/config.yml):

Debugging/Live Reloading

$ pipenv run dev

Running

$ pipenv run start

Formatting

$ invoke black

Sort Imports

$ invoke sort

Linting

$ invoke check

Unit Testing

$ invoke test

End to End Tests

$ invoke e2e

Generate Test Coverage

$ invoke coverage

Docker

Setting up Docker is quite straight forward -- unless you are using Windows 10 Home (more on this later).

Run these commands.

docker-compose build
docker-compose up

If you are using a non-supported OS for Docker, you would need to use Docker Toolkit. Once you have it set up, if you are not able to access the container itself, allow port 8080 in your VM. Reference

Projects Using This API

Let me know if you are using the API! It means a great deal.

License

See LICENSE.md for information regarding usage and attribution.