Skip to main content

Algolia Search API Client for Python.

Project description

The readme/code you are seeing it's part of upcoming release

Algolia API Client Python v2

Algolia Search is a hosted search engine capable of delivering real-time results from the first keystroke.

This readme/code introduces the upcoming Algolia API Client Python v2, the next major release of our API Client. This release includes several new features along with the latest bug fixes and improvements:

  • Supports Python: 2.7, 3.4, 3.5, 3.6, and 3.7.
  • Works in synchronous and asynchronous environments.
  • Tons of new methods: waitable response objects, replace_all_objects,clear_objects, and more!

Development Status: 4 - Beta.

Upgrade Guide: Upgrade Guide

You'd like to contribute? Before start, we want to let you know that your feedback is important to us! Please consider start using this v2 today! Found a bug or see something that can improved? Report it here: github.com/algolia/algoliasearch-client-python/issues.

First, install Algoliasearch - API Client Python v2:

pip install --pre algoliasearch

Example with synchronous usage:

import os

from algoliasearch.search_client import SearchClient

client = SearchClient.create(
    'ALGOLIA_APPLICATION_ID',
    'ALGOLIA_ADMIN_KEY'
)

index = client.init_index('articles')

index.save_objects([
    {'objectID': 1, 'firstname': 'Jimmie', 'lastname': 'Barninger'},
    {'objectID': 2, 'firstname': 'Warren', 'lastname': 'Speach'}
]).wait()

hits = index.search('Jimmie')

print(hits)

Example with asynchronous usage:

First, require asynchronous libraries:

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

Then, asynchronous methods are 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
... ...
import asyncio

from algoliasearch.search_client import SearchClient
from algoliasearch.responses import MultipleResponse

app_id = 'ALGOLIA_APPLICATION_ID'
api_key = 'ALGOLIA_ADMIN_KEY'

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'}
        ])

        for raw_response in response.raw_responses:
            await index.wait_task_async(raw_response['taskID'])

        print(await index.search_async(''))

asyncio.run(main())

License

Algolia API Client Python is an open-sourced software licensed under the MIT license.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algoliasearch-2.0.0b4.tar.gz (18.7 kB view hashes)

Uploaded Source

Built Distribution

algoliasearch-2.0.0b4-py2.py3-none-any.whl (28.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page