Event Registry Python Client

9.1 · active · verified Fri Apr 17

The `eventregistry` library is a Python client for interacting with the Event Registry API (eventregistry.org). It allows users to query for news articles, events, mentions, and perform text analytics. The current version is 9.1, and releases are made periodically to add new features and improve existing functionality.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `EventRegistry` client with an API key, construct a `QueryArticles` object to search for articles, execute the query, and print the titles of the retrieved articles. Ensure your API key is correctly set.

import os
from eventregistry import EventRegistry, QueryArticles

# Get API key from environment variable or replace with your key
ER_API_KEY = os.environ.get('EVENT_REGISTRY_API_KEY', 'YOUR_API_KEY')

if ER_API_KEY == 'YOUR_API_KEY':
    print("Warning: Please replace 'YOUR_API_KEY' with your actual Event Registry API key or set the EVENT_REGISTRY_API_KEY environment variable.")
    exit()

# Initialize EventRegistry
er = EventRegistry(apiKey=ER_API_KEY)

# Create a query for articles about 'Python programming' in English
q = QueryArticles(keywords = 'Python programming', lang = 'eng')

# Execute the query and get up to 10 articles
q.setRequestedResults(10)
res = er.execQuery(q)

# Print article titles
if res and 'articles' in res and 'results' in res['articles']:
    print(f"Found {len(res['articles']['results'])} articles:")
    for article in res['articles']['results']:
        print(f"- {article['title']}")
else:
    print("No articles found or an error occurred.")

view raw JSON →