algoliasearch package is version 4.
This page helps you upgrade from version 3
and explains the breaking changes you need to address.
Algolia generates the version 4 clients from OpenAPI specifications,
which provides consistent behavior across all languages and up-to-date API coverage.
The main architectural change is the removal of the init_index pattern:
all methods are now on the client instance directly, with index_name as a parameter.
For the full list of changes, see the Python changelog.
Update your dependencies
Update thealgoliasearch package to version 4:
Command line
Update imports
The import path changed fromalgoliasearch.search_client to algoliasearch.search.client.
Python
Python
Update client initialization
Client creation changed in version 4. TheSearchClient.create() factory method is gone.
Create a SearchClientSync instance for synchronous code
or a SearchClient instance for asynchronous code.
Python
SearchClientSync is the synchronous client,
while SearchClient (without suffix) is the asynchronous client.
The asynchronous client supports the
async with syntax
to automatically close open connections.
Understand the new API surface
Version 4 introduces three major changes to the API surface:- No more
init_index. Version 3 relied on an index object with methods called on it. In version 4, all methods belong to theclientinstance, withindex_nameas a parameter. - Synchronous and asynchronous clients.
Version 4 includes
SearchClientSyncfor synchronous code andSearchClientfor asynchronous code (withasync/await). Version 3 only had a synchronous client. - Typed model classes.
Version 4 includes model classes like
SearchParamsandIndexSettingsfor all API parameters (see Use model classes or dictionaries).
Python
Use model classes or dictionaries
Version 4 methods accept both model classes and dictionaries as parameters.Python
Update search calls
Search a single index
Theindex.search() method is now client.search_single_index().
Pass the index name and search parameters as separate arguments:
Python
Search multiple indices
Theclient.multiple_queries() method is now client.search().
Each request in the list requires an indexName:
Python
Search for facet values
Theindex.search_for_facet_values() method becomes client.search_for_facet_values()
with an index_name parameter:
Python
Update indexing operations
In version 4, indexing methods are on the client instead of the index object, withindex_name as a parameter.
Add or replace records
Python
Partially update records
Python
Delete records
Python
Update settings, synonyms, and rules
Get and set settings
Python
Save synonyms and rules
Python
In version 3,
index.replace_all_rules() and index.replace_all_synonyms() replaced all rules or synonyms.
In version 4, use client.save_rules() or client.save_synonyms() with the clear_existing_rules or replace_existing_synonyms parameter set to True.Update index management
Thecopy_index, move_index, copy_rules, copy_synonyms, and copy_settings
methods are all replaced by a single operation_index method.
Copy an index
Python
Move (rename) an index
Python
Copy only rules or settings
In version 4, use thescope parameter to limit the operation to specific data:
Python
Check if an index exists
In version 3, you could check if an index existed using theexists method on the index object.
In version 4, use the index_exists helper method on the client:
Python
Update task handling
Version 3 supported chaining.wait() on operations.
Version 4 replaces this pattern with dedicated wait helpers.
Python
wait_for_task: wait until indexing operations are done.wait_for_app_task: wait for application-level tasks.wait_for_api_key: wait for API key operations.
Helper method changes
The following sections document breaking changes in helper method signatures and behavior between version 3 and version 4.replace_all_objects
The safe option has been removed. In version 3, passing safe=True in request_options caused the helper to wait after each step. In version 4, the helper always waits—equivalent to the previous safe=True behavior.
The scopes parameter is now required and must be passed explicitly.
Python
save_objects
The autoGenerateObjectIDIfNotExist option has been removed. In version 4, every object must include an object_id, or you must use chunked_batch with action="addObject" if you want the API to generate object IDs.
Two new optional parameters are available:
wait_for_tasks(waits for all indexing tasks before returning, defaultFalse)batch_size(controls objects per API call, default1,000)
Python
delete_objects
Two new optional parameters are available:
wait_for_tasks(defaultFalse)batch_size(default1,000)
Python
partial_update_objects
The create_if_not_exists parameter moved from request_options to an explicit keyword argument.
Python
browse_objects, browse_rules, browse_synonyms
These helpers now use an aggregator callback instead of returning an iterator. The helper calls aggregator with each page of results as it paginates.
Python
generate_secured_api_key and get_secured_api_key_remaining_validity
Both methods were static methods on the index class in version 3. In version 4 they are instance methods on the client.
Python
wait_for_task
The helper was renamed from wait_task to wait_for_task, moved to the client, and now accepts explicit max_retries (default 50) and timeout parameters. In version 3 it retried indefinitely with no cap.
Python
wait_for_app_task
This is a new helper in version 4.
Python
wait_for_api_key
This is a new standalone helper in version 4.
Python
index_exists
The helper was renamed from exists() on the index object to index_exists() on the client.
Python
chunked_batch
chunked_batch is now a public helper. In version 3, chunking was an internal detail of save_objects. The action parameter defaults to Action.ADDOBJECT and wait_for_tasks defaults to False.
Python
account_copy_index
In version 3, AccountClient.copy_index allowed copying an index between two different Algolia applications. It accepted two SearchIndex objects and raised if the destination already existed or if both indices were on the same app.
In version 4, AccountClient is removed. You can compose existing helpers across two clients to achieve the same result.
Python
save_objects_with_transformation
New in version 4. Routes objects through the Algolia Push connector. Requires transformation_region at client initialization.
Python
replace_all_objects_with_transformation
New in version 4. Atomically replaces all objects via the Push connector (copy settings/rules/synonyms to a temp index → push objects → move back). Requires transformation_region at client initialization.
Python
partial_update_objects_with_transformation
New in version 4. Routes partial updates through the Push connector. The create_if_not_exists parameter defaults to False.
Python
Method changes reference
The following tables list all method names that changed between version 3 and version 4.Search API client
| Version 3 (legacy) | Version 4 (current) | |
|---|---|---|
client.add_api_key | → | client.add_api_key |
client.add_api_key.wait | → | client.wait_for_api_key |
client.clear_dictionary_entries | → | client.batch_dictionary_entries |
client.copy_index | → | client.operation_index |
client.copy_rules | → | client.operation_index |
client.copy_synonyms | → | client.operation_index |
client.delete_api_key | → | client.delete_api_key |
client.delete_dictionary_entries | → | client.batch_dictionary_entries |
client.generate_secured_api_key | → | client.generate_secured_api_key |
client.get_api_key | → | client.get_api_key |
client.get_secured_api_key_remaining_validity | → | client.get_secured_api_key_remaining_validity |
client.list_api_keys | → | client.list_api_keys |
client.list_indices | → | client.list_indices |
client.move_index | → | client.operation_index |
client.multiple_batch | → | client.multiple_batch |
client.multiple_queries | → | client.search |
client.replace_dictionary_entries | → | client.batch_dictionary_entries |
client.restore_api_key | → | client.restore_api_key |
client.save_dictionary_entries | → | client.batch_dictionary_entries |
client.update_api_key | → | client.update_api_key |
index.batch | → | client.batch |
index.browse_objects | → | client.browse_objects |
index.browse_rules | → | client.browse_rules |
index.browse_synonyms | → | client.browse_synonyms |
index.clear_objects | → | client.clear_objects |
index.clear_rules | → | client.clear_rules |
index.clear_synonyms | → | client.clear_synonyms |
index.copy_settings | → | client.operation_index |
index.delete | → | client.delete_index |
index.delete_by | → | client.delete_by |
index.delete_object | → | client.delete_object |
index.delete_objects | → | client.delete_objects |
index.delete_rule | → | client.delete_rule |
index.delete_synonym | → | client.delete_synonym |
index.exists | → | client.index_exists |
index.find_object | → | client.search_single_index |
index.get_object | → | client.get_object |
index.get_objects | → | client.get_objects |
index.get_rule | → | client.get_rule |
index.get_settings | → | client.get_settings |
index.get_synonym | → | client.get_synonym |
index.get_task | → | client.get_task |
index.partial_update_object | → | client.partial_update_object |
index.partial_update_objects | → | client.partial_update_objects |
index.replace_all_objects | → | client.replace_all_objects |
index.replace_all_rules | → | client.save_rules |
index.replace_all_synonyms | → | client.save_synonyms |
index.save_object | → | client.save_object |
index.save_objects | → | client.save_objects |
index.save_rule | → | client.save_rule |
index.save_rules | → | client.save_rules |
index.save_synonym | → | client.save_synonym |
index.save_synonyms | → | client.save_synonyms |
index.search | → | client.search_single_index |
index.search_for_facet_values | → | client.search_for_facet_values |
index.search_rules | → | client.search_rules |
index.search_synonyms | → | client.search_synonyms |
index.set_settings | → | client.set_settings |
index.{operation}.wait | → | client.wait_for_task |
Recommend API client
| Version 3 (legacy) | Version 4 (current) | |
|---|---|---|
client.get_frequently_bought_together | → | client.get_recommendations |
client.get_recommendations | → | client.get_recommendations |
client.get_related_products | → | client.get_recommendations |