The Insights API client is part of the algoliasearch package. You can install this package with pip:

1
pip install 'algoliasearch>=4,<5'

To use the Insights client, add this import to your files:

1
2
from algoliasearch.insights.client import InsightsClientSync
from json import loads

To create an instance of the client:

1
2
3
4
# In an asynchronous context, you can use InsightsClient instead, which exposes the exact same methods.
client = InsightsClientSync(
    "ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
)

Replace ALGOLIA_APPLICATION_ID_REGION with your Algolia application’s analytics region: us for the United States or de for Europe. You can check your analytics region in the Infrastructure > Analytics section of the Algolia dashboard.

Async code

To use the Insights client in async environments, add these imports instead:

1
2
import asyncio
from algoliasearch.insights.client import InsightsClient

The client supports the async with statement to automatically close open connections.

1
2
3
async def run():
    async with InsightsClient(ALGOLIA_APPLICATION_ID, ALGOLIA_API_KEY) as client:
        # client.search(...)

The method names are the same for synchronous and asynchronous methods.

List of methods

Each method makes one request to the Insights API.

Events

User tokens

Did you find this page helpful?
Python API clients v4