Install the Python API client


Install the Python client using pip:

pip install --upgrade algoliasearch

Language-specific notes

We implemented an asynchronous version of the client that may suit your need if you are using a framework such as aiohttp in your backend. This version can be found here.

Unreachable hosts

If you are seeing an error for Unreachable hosts when pushing data to Algolia, this is caused by PyOpenSSL and older versions of Python. You can see more information here.

To fix, either upgrade your Python version or your urllib3.

Init Index

To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.

from algoliasearch import algoliasearch

client = algoliasearch.Client("YourApplicationID", 'YourAPIKey')
index = client.init_index('your_index_name')

If you use this API Client with Google AppEngine (thanks @apassant), it will use urlfetch instead of using the request module. Please be aware of the limits of urlfetch, and note that SSL certificates aren’t verified for calls to domains other than due to the lack of SNI support in urlfetch. To run unit tests on the AppEngine stub, please define an APPENGINE_RUNTIME enviroment variable.

You need to replace your_index_name by the name of the index you want to use. If you want to target an existing index you can find the name from the dashboard. If the index does not exist you can choose any name and it will be created when you perform an add objects or a set settings operation.

If an api key is displayed in the previous snippet it is your ADMIN API Key. To maintain security, never use your ADMIN API Key on your frontend or share it with anyone. In your frontend, use the SEARCH ONLY API Key or any other key that has search only rights.

Make sure you don’t use any sensitive or personally identifiable information (PII) as your index name, including customer names, user IDs, or email addresses. Index names appear in network requests and should be considered publicly available.