liveBook · Manning

Contract

As explained in Effective Data Analysis

An API is a defined programmatic interface through which software requests data or operations from another software system or service.

An API (application programming interface) is a defined way for software systems to communicate. A request asks for data or an operation; the API’s protocols determine the response format. For analysts, APIs offer a way to bring external, up-to-date data into Python or a data warehouse instead of repeatedly collecting it through a website. section 10.1 section 10.4

A browser interface may be enough for a one-time download. If stakeholders need a refreshed deliverable, an API can make retrieval repeatable. For example, a city agency predicting daily rat sightings could use forecast data rather than manually copying each new weather forecast. section 10.1.1 section 10.1.2

A practical retrieval workflow is:

  • Read the API documentation and identify an endpoint for the data needed. section 10.1.1
  • Call the endpoint with Python’s requests library, then inspect the response and parse its JSON. section 10.1.1
  • Select relevant fields, flatten nested records into a pandas dataframe, and reshape them to match the analytical question. section 10.1.1 section 10.4
import requests
import json    #1

url = "https://api.weather.gov/gridpoints/OKX/34,36/forecast"    #2
response = requests.get(url)    #3
print(response)   #4

This forecast request shows the initial call; the response still needs to be inspected and processed before it becomes an analytical dataset. section 10.1.1

The decision to use an API depends on more than whether one exists. Weigh setup effort against refresh frequency, data volume, and available automation. A public data portal’s CSV export may suit a static analysis, while its API may suit regularly updated records. Check whether authentication, pagination, or rate limits affect the data you can retrieve, and verify that the response contains the records you intended. section 10.1.2 section 10.3.3 section 10.4

How Effective Data Analysis covers it

How deep it goes
Works through a forecast request, JSON inspection, and dataframe preparation; also weighs whether automation is worth the setup effort.
Examples
Uses a National Weather Service forecast and NYC Open Data rat-sighting records to illustrate refreshed datasets.
What it assumes
Assumes familiarity with Python analysis while defining APIs and walking through a request and its response.
What you can do after
Apply it via Python requests to retrieve and prepare API data, then evaluate whether automated retrieval serves the stakeholder’s needs.
How it connects
Connects APIs to JSON, pandas dataframes, data warehouses, public data portals, and ETL pipelines.

Also explained in

Compare how 44 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Data Analysis. The section links point to the parts of the book it draws on.