API Reference / API Methods / Asynchronous environments
Apr. 23, 2019

Asynchronous environments

Algolia’s Python API Client provides asynchronous methods built on top of the Python 3.4+ asyncio framework. However, to make them available, you need to install the following asynchronous libraries:

$
pip install 'asyncio>=3.4,<4.0' 'aiohttp>=2.0,<4.0' 'async_timeout>=2.0,<4.0'

Then, asynchronous methods will be available using the _async suffix:

Synchronous Asynchronous
search search_async
save_objects save_objects_async
set_settings set_settings_async
save_synonyms save_synonyms_async
... ...

Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import asyncio

from algoliasearch.search_client import SearchClient

app_id = 'YourApplicationID'
api_key = 'YourAdminAPIKey'

async def main():
    async with SearchClient.create(app_id, api_key) as client:
        index = client.init_index('articles')

        response = await index.save_objects_async([
            {'objectID': 1, 'foo': 'bar'},
            {'objectID': 2, 'foo': 'foo'}
        ])

        results = await index.search_async('')

        print(results)

asyncio.run(main())

Did you find this page helpful?

Python