Obtaining "This Day in History" Data with Python

← Day in History API

What happened on your birthday? On the day the moon landing took place? The Day in History API serves structured historical events, births, and deaths for any date — no API key, no signup, just clean JSON over HTTPS.

Obtaining the Client Object

One can obtain the slug-name of the API via the Zingu APIs web portal. Then one can create a client object like so:

import zingu_apis

api = zingu_apis.api("dayinhistory.dev:day-in-history-api")

What the API Offers

tools = api.tools()
print(tools)

The .tools() method returns a list of endpoints with description from the Zingu database. This command does not connect to the API directly. In this example one can see from the returned dictionary that the API offers 6 endpoints corresponding to events, births, deaths for today or a specific day.

Fetching Data Without the Boilerplate

Calling a paginated API normally requires a loop that tracks page numbers, follows next links, and collects results. The zingu-apis package handles all of that — plus retries, error handling, and analytics — in one call:

import zingu_apis

api = zingu_apis.api("dayinhistory.dev:day-in-history-api")
result = api.fetch("/today/events/")

# See what fields are available
print(result)

# Access a single item directly
print(result[0]["title"])

# Or unwrap: single-object APIs return the dict, multi-item APIs return the list
print(result.data)

Behind the scenes

The fetch() method handles:

Result Object

Every result has the same shape:

You can iterate over the result object directly, index into it, or print() it for a summary.

Links

Going Further