Search API client
The Search API client is part of the algoliasearch package.
You can install this package with pip:
1
pip install 'algoliasearch>=4,<5'
To use the Search client, add this import to your files:
1
2
from algoliasearch.search.client import SearchClientSync
from json import loads
To create an instance of the client:
1
2
# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client = SearchClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
Async code
To use the Search client in async environments, add these imports instead:
1
2
import asyncio
from algoliasearch.search.client import SearchClient
The client supports the async with statement to automatically close open connections.
1
2
3
async def run():
async with SearchClient(ALGOLIA_APPLICATION_ID, ALGOLIA_API_KEY) as client:
# client.search(...)
The method names are the same for synchronous and asynchronous methods.
Indices
Algolia automatically creates a new index when you add records, rules, or synonyms, or when you change settings for an index that doesn’t yet exist. You don’t need to create indices explicitly.
Don’t include sensitive or personally identifiable information (PII) in your index names. They appear in network requests and are publicly visible.
List of methods
Each method makes one request to the Search API. The Search API client also includes helper methods that wrap one or more of these methods. For more information, see Helper methods.
Search
| client.search_single_index | Search an index |
| client.search | Search multiple indices |
| client.search_for_facet_values | Search for facet values |
| client.browse | Browse for records |
Records
| client.save_object | Add a new record (with auto-generated object ID) |
| client.get_object | Retrieve a record |
| client.add_or_update_object | Add or replace a record |
| client.delete_object | Delete a record |
| client.delete_by | Delete records matching a filter |
| client.clear_objects | Delete all records from an index |
| client.partial_update_object | Add or update attributes |
| client.batch | Batch indexing operations on one index |
| client.multiple_batch | Batch indexing operations on multiple indices |
| client.get_objects | Retrieve records |
Indices
| client.delete_index | Delete an index |
| client.get_settings | Retrieve index settings |
| client.set_settings | Update index settings |
| client.get_task | Check task status |
| client.operation_index | Copy or move an index |
| client.list_indices | List indices |
Synonyms
| client.get_synonym | Retrieve a synonym |
| client.save_synonym | Create or replace a synonym |
| client.delete_synonym | Delete a synonym |
| client.save_synonyms | Create or replace synonyms |
| client.clear_synonyms | Delete all synonyms |
| client.search_synonyms | Search for synonyms |
API keys
| client.list_api_keys | List API keys |
| client.add_api_key | Create an API key |
| client.get_api_key | Retrieve API key permissions |
| client.update_api_key | Update an API key |
| client.delete_api_key | Delete an API key |
| client.restore_api_key | Restore an API key |
Rules
| client.get_rule | Retrieve a rule |
| client.save_rule | Create or replace a rule |
| client.delete_rule | Delete a rule |
| client.save_rules | Create or update rules |
| client.clear_rules | Delete all rules |
| client.search_rules | Search for rules |
Dictionaries
| client.batch_dictionary_entries | Add or delete dictionary entries |
| client.search_dictionary_entries | Search dictionary entries |
| client.get_dictionary_settings | Retrieve dictionary settings |
| client.set_dictionary_settings | Update dictionary settings |
| client.get_dictionary_languages | List available languages |
Clusters
| client.list_user_ids | List user IDs |
| client.assign_user_id | Assign or move a user ID |
| client.batch_assign_user_ids | Assign multiple userIDs |
| client.get_top_user_ids | Get top user IDs |
| client.get_user_id | Retrieve user ID |
| client.remove_user_id | Delete user ID |
| client.list_clusters | List clusters |
| client.search_user_ids | Search for user IDs |
| client.has_pending_mappings | Get migration and user mapping status |
Vaults
| client.get_sources | List allowed sources |
| client.replace_sources | Replace allowed sources |
| client.append_source | Add a source |
| client.delete_source | Delete a source |
Advanced
| client.get_logs | Retrieve log entries |
| client.get_app_task | Check application task status |