[](https://badge.fury.io/py/algoliasearchasync)
[](https://coveralls.io/github/algolia/algoliasearch-client-python-async?branch=master)
# Algolia Asynchronous Python Client
This package is designed to replace the
[`algoliasearch`](https://github.com/algolia/algoliasearch-client-python)
package in asynchronous environments.
This package is only compatible with python 3.4 and onward.
## What it does
- Is compatible with python `asyncio`.
- Provide asynchronous alternatives to most of the client methods.
All those methods are just suffixed by `_async` (`search_async`,
`add_object_async`, etc.)
- Still provide synchronous versions of the methods.
- Uses `aiohttp` as the HTTP underlying library.
- Uses `__aexit__` to avoid manually closing `aiohttp` sessions with
python >= 3.5.1.
## What it does **not**
- Implement the `search_disjunctive_faceting` method.
- Support task canceling (yet).
## Installation and Dependencies
Most of the logic of the synchronous client is being used here, so this
client depends on the synchronous one. It also depends on `aiohttp`.
To install this package: `pip install algoliasearchasync`.
## Documentation
All the asynchronous functions have the same names as the synchronous ones
with `_async` appended. Synchronous methods keep the same name.
Arguments taken by the asynchronous functions are the same as the synchronous
one, for documentation on the behavior of each function please see:
- [Synchronous python client](https://github.com/algolia/algoliasearch-client-python)
- [Algolia documentation](https://www.algolia.com/doc)
## Examples
With python >= 3.4
```python
import asyncio
from algoliasearchasync import ClientAsync
@asyncio.coroutine
def main(terms):
client = ClientAsync('<APP_ID>', '<API_KEY>')
index = client.init_index('<INDEX_NAME>')
# Create as many searches as there is terms.
searches = [index.search_async(term) for term in terms]
# Store the aggregated results.
s = yield from asyncio.gather(*searches)
# Client must be closed manually before exiting the program.
yield from client.close()
# Return the aggregated results.
return s
terms = ['<TERM2>', '<TERM2>']
loop = asyncio.get_event_loop()
# Start and wait for the tasks to complete.
complete = loop.run_until_complete(asyncio.gather(*searches))
for term, search in zip(terms, complete):
print('Results for: {}'.format(term))
# Display the field '<FIELD>' of each result.
print('\n'.join([h['<FIELD>'] for h in search['hits']]))
```
With python >= 3.5.1
```python
import asyncio
from algoliasearchasync import ClientAsync
# Define a coroutine to be able to use `async with`.
async def main(terms):
# Scope the client for it to be closed automatically.
async with ClientAsync('<APP_ID>', '<API_KEY>') as client:
index = client.init_index('<INDEX_NAME>')
# Create as many searches as there is terms.
searches = [index.search_async(term) for term in terms]
# Return the aggregated results.
return await asyncio.gather(*searches)
terms = ['<TERM1>', '<TERM2>']
loop = asyncio.get_event_loop()
# Start and wait for the tasks to complete.
complete = loop.run_until_complete(main(terms))
for term, search in zip(terms, complete):
print('Results for {}'.format(term))
# Display the field '<FIELD>' of each result.
print('\n'.join([h['<FIELD>'] for h in search['hits']]))
```
Metadata
Release files for algoliasearchasync 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| algoliasearchasync-1.3.2.tar.gz | 6.6 kB | Without provenance | Details for algoliasearchasync-1.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| algoliasearchasync-1.3.2-py3-none-any.whl | Python 3 | none | any | Details for algoliasearchasync-1.3.2-py3-none-any.whl |
Total release size: 16.1 kB
Release files / algoliasearchasync-1.3.2.tar.gz
| Download URL | algoliasearchasync-1.3.2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36079d1ccc3a9eb787b5c72169dc38d9dfa2a4d0b6e22440cc5c227b33330af7
|
|
BLAKE2b-256 checksum How to use checksums |
02ff77a04939ae32a0390f90bc9ce66609105d7fb18d0a63f6ba6ef9cf4b09f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / algoliasearchasync-1.3.2-py3-none-any.whl
| Download URL | algoliasearchasync-1.3.2-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1877df7fc109f56ba7b035f380de37e077a68662f0df4ed696222aacd7daa88
|
|
BLAKE2b-256 checksum How to use checksums |
74a9b370535d9921125ee1019901dc0f87c273c7e26f9bf3f106ecb7f1c5befe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for algoliasearchasync 1.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.