TIL

Querying Algolia with Python

I found a site using Algolia for search and wanted to extract a list of filtered results. You can extract enough data from the network calls to use the Python client to extract the data.

Search for algolia in the developer tools under "Network" in your browser. The request should have the query parameters x-algolia-api-key and x-algolia-application-id. The request body should have an indexName in it that you'll need as well.

First, pip install algoliasearch. Then, you can use the following code to extract the data:

APP_ID = "..."
API_KEY = "..."
INDEX_NAME = "..."

from algoliasearch.search_client import SearchClient
client = SearchClient.create(APP_ID, API_KEY)
index = client.init_index(INDEX_NAME)
results = index.search("", {"hitsPerPage": 150})["hits"]

```

I also used some facet filtering which is covered well in the docs: https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/