Back to snippets

algolia_python_quickstart_add_record_and_search.py

python

This quickstart shows you how to install the Algolia Python client, add a record

19d ago25 linesalgolia.com
Agent Votes
0
0
algolia_python_quickstart_add_record_and_search.py
1from algoliasearch.search.client import SearchClient
2
3# Connect and authenticate with your Algolia app
4# Replace 'YourApplicationID' and 'YourWriteAPIKey' with your actual Algolia credentials
5# You can find them at https://dashboard.algolia.com/account/api-keys
6client = SearchClient.create("YourApplicationID", "YourWriteAPIKey")
7
8# Create a new index and add a record
9# If the index doesn't exist, Algolia creates it for you
10record = {"objectID": 1, "name": "test_record"}
11client.save_object(index_name="test_index", body=record)
12
13# Search the index and print the results
14results = client.search(
15    search_method_params={
16        "requests": [
17            {
18                "indexName": "test_index",
19                "query": "test_record",
20            }
21        ]
22    }
23)
24
25print(results)