Event Registry Python SDK

repository·master·Indexed 42 days ago

https://github.com/eventregistry/event-registry-python

A Python SDK for accessing news data via the Event Registry API. It enables developers to query articles and events using filters for sentiment, location, concepts, and categories, and provides tools to retrieve trending concepts.

Tokens
953
Snippets
7
Records
7
Agent score
4%

What's inside Event Registry

  1. Authenticate with an API key

    master

    All queries to the Event Registry API require an API key. You can obtain a key (including a free tier) from the Event Registry website. When initializing the EventRegistry class, pass your key to the apiKey parameter.

    from eventregistry import *
    er = EventRegistry(apiKey = 'YOUR_API_KEY')
  2. Install the eventregistry package

    master

    You can install the eventregistry package using pip or by cloning the GitHub repository and running the setup script.

    Using pip:

    pip install eventregistry

    From source:

    1. Clone the repository from GitHub.
    2. Run the installation script:
    python setup.py install
    pip install eventregistry
  3. Search for articles using QueryArticlesIter

    master

    Use QueryArticlesIter to search for articles or blog posts. You can filter by keywords, concepts, categories, sentiment, and location.

    Key features:

    • Keywords: Use QueryItems.OR([...]) to search for multiple phrases.
    • Concepts/Categories: Use er.getConceptUri() or er.getCategoryUri() to get the required URIs for filtering.
    • Locations: Use er.getLocationUri() to filter by geographic area.
    • Execution: Call .execQuery(er, ...) on the query object. Use maxItems to limit results (remove it to get all available results).
    from eventregistry import *
    er = EventRegistry(apiKey = 'YOUR_API_KEY')
    
    # Example: Search for articles mentioning specific keywords in the USA
    usUri = er.getLocationUri("USA")
    q = QueryArticlesIter(
        keywords = QueryItems.OR(["George Clooney", "Sandra Bullock"]),
        minSentiment = 0.4,
        sourceLocationUri = usUri,
        dataType = ["news", "blog"]
    )
    
    for art in q.execQuery(er, sortBy = "date", maxItems = 500):
        print(art)
  4. Search for events using QueryEvents

    master

    Use QueryEvents to find events related to specific keywords.

    To control the output, use .setRequestedResult() with a RequestEventsInfo object to specify sorting and the number of events to return.

    from eventregistry import *
    er = EventRegistry(apiKey = 'YOUR_API_KEY')
    
    q = QueryEvents(keywords = "Star Wars")
    q.setRequestedResult(RequestEventsInfo(sortBy = "date", count = 50))
    
    # Execute and print the list of events
    print(er.execQuery(q))
  5. Get trending concepts

    master

    Use GetTrendingConcepts to retrieve the most popular topics currently appearing in the news.

    from eventregistry import *
    er = EventRegistry(apiKey = 'YOUR_API_KEY')
    
    # Get top 10 trending concepts in the news
    q = GetTrendingConcepts(source = "news", count = 10)
    print(er.execQuery(q))