Metadata-Version: 2.1
Name: algoliasearch
Version: 1.17.0
Summary: Algolia Search API Client for Python
Home-page: https://github.com/algolia/algoliasearch-client-python
Author: Algolia Team
Author-email: support@algolia.com
License: MIT License
Keywords: algolia,pyalgolia,search,backend,hosted,cloud,full-text search,faceted search
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Development Status :: 5 - Production/Stable
Requires-Dist: requests (>=2.9.1)

Algolia Search API Client for Python
====================================

`Algolia Search <https://www.algolia.com>`__ is a hosted full-text,
numerical, and faceted search engine capable of delivering realtime
results from the first keystroke.

The **Algolia Search API Client for Python** lets you easily use the
`Algolia Search REST
API <https://www.algolia.com/doc/rest-api/search>`__ from your Python
code.

`Build
Status <https://travis-ci.org/algolia/algoliasearch-client-python>`__
`PyPI version <http://badge.fury.io/py/algoliasearch>`__ `Coverage
Status <https://coveralls.io/r/algolia/algoliasearch-client-python>`__

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 <https://github.com/algolia/algoliasearch-client-python-async>`__.

API Documentation
-----------------

You can find the full reference on `Algolia’s
website <https://www.algolia.com/doc/api-client/python/>`__.

1. `Install <#install>`__

2. `Quick Start <#quick-start>`__

3. `Push data <#push-data>`__

4. `Configure <#configure>`__

5. `Search <#search>`__

6. `Search UI <#search-ui>`__

7. `List of available methods <#list-of-available-methods>`__

Getting Started
===============

Install
-------

Install AlgoliaSearch using pip:

.. code:: bash

   pip install --upgrade algoliasearch

Quick Start
-----------

In 30 seconds, this quick start tutorial will show you how to index and
search objects.

Initialize the client
~~~~~~~~~~~~~~~~~~~~~

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 <https://www.algolia.com/api-keys>`__.

.. code:: python

   from algoliasearch import algoliasearch

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

**Note:** If you use this API Client with Google AppEngine (Thanks
[@apassant](https://github.com/apassant)), it will use ``urlfetch``
instead of using the ``request`` module. Please be aware of `urlfetch’s
limits <https://cloud.google.com/appengine/docs/python/urlfetch/>`__,
and note that SSL certificates will not be verified for calls to domains
other than algolia.net due to the lack of SNI support in ``urlfetch``.
To run unit tests on the AppEngine stub, please define an
``APPENGINE_RUNTIME`` enviroment variable.

Push data
---------

Without any prior configuration, you can start indexing `500
contacts <https://github.com/algolia/datasets/blob/master/contacts/contacts.json>`__
in the ``contacts`` index using the following code:

.. code:: python

   index = client.init_index("contact")
   batch = json.load(open('contacts.json'))
   index.add_objects(batch)

Configure
---------

Settings can be customized to fine tune the search behavior. For
example, you can add a custom sort by number of followers to further
enhance the built-in relevance:

.. code:: python

   index.set_settings({"customRanking": ["desc(followers)"]})

You can also configure the list of attributes you want to index by order
of importance (most important first).

**Note:** The Algolia engine is designed to suggest results as you type,
which means you’ll generally search by prefix. In this case, the order
of attributes is very important to decide which hit is the best:

.. code:: python

   index.set_settings({"searchableAttributes": ["lastname", "firstname", "company",
                                            "email", "city", "address"]})

Search
------

You can now search for contacts using ``firstname``, ``lastname``,
``company``, etc. (even with typos):

.. code:: python

   # search by firstname
   print index.search("jimmie")
   # search a firstname with typo
   print index.search("jimie")
   # search for a company
   print index.search("california paint")
   # search for a firstname & company
   print index.search("jimmie paint")

Search UI
---------

**Warning:** If you are building a web application, you may be more
interested in using one of our `frontend search UI
libraries <https://www.algolia.com/doc/guides/search-ui/search-libraries/>`__

The following example shows how to build a front-end search quickly
using
`InstantSearch.js <https://community.algolia.com/instantsearch.js/>`__

index.html
~~~~~~~~~~

.. code:: html

   <!doctype html>
   <head>
     <meta charset="UTF-8">
     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3/dist/instantsearch.min.css">
     <!-- Always use `2.x` versions in production rather than `2` to mitigate any side effects on your website,
     Find the latest version on InstantSearch.js website: https://community.algolia.com/instantsearch.js/v2/guides/usage.html -->
   </head>
   <body>
     <header>
       <div>
          <input id="search-input" placeholder="Search for products">
          <!-- We use a specific placeholder in the input to guides users in their search. -->

     </header>
     <main>


     </main>

     <script type="text/html" id="hit-template">

         <p class="hit-name">{{{_highlightResult.firstname.value}}} {{{_highlightResult.lastname.value}}}</p>

     </script>

     <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3/dist/instantsearch.min.js"></script>
     <script src="app.js"></script>
   </body>

app.js
~~~~~~

.. code:: js

   var search = instantsearch({
     // Replace with your own values
     appId: 'YourApplicationID',
     apiKey: 'YourSearchOnlyAPIKey', // search only API key, no ADMIN key
     indexName: 'contacts',
     urlSync: true,
     searchParameters: {
       hitsPerPage: 10
     }
   });

   search.addWidget(
     instantsearch.widgets.searchBox({
       container: '#search-input'
     })
   );

   search.addWidget(
     instantsearch.widgets.hits({
       container: '#hits',
       templates: {
         item: document.getElementById('hit-template').innerHTML,
         empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
       }
     })
   );

   search.start();

List of available methods
-------------------------

.. _search-1:

Search
~~~~~~

-  `Search an
   index <https://algolia.com/doc/api-reference/api-methods/search/?language=python>`__
-  `Search for facet
   values <https://algolia.com/doc/api-reference/api-methods/search-for-facet-values/?language=python>`__
-  `Search multiple
   indexes <https://algolia.com/doc/api-reference/api-methods/multiple-queries/?language=python>`__
-  `Browse an
   index <https://algolia.com/doc/api-reference/api-methods/browse/?language=python>`__

Indexing
~~~~~~~~

-  `Add
   objects <https://algolia.com/doc/api-reference/api-methods/add-objects/?language=python>`__
-  `Update
   objects <https://algolia.com/doc/api-reference/api-methods/update-objects/?language=python>`__
-  `Partial update
   objects <https://algolia.com/doc/api-reference/api-methods/partial-update-objects/?language=python>`__
-  `Delete
   objects <https://algolia.com/doc/api-reference/api-methods/delete-objects/?language=python>`__
-  `Delete
   by <https://algolia.com/doc/api-reference/api-methods/delete-by/?language=python>`__
-  `Get
   objects <https://algolia.com/doc/api-reference/api-methods/get-objects/?language=python>`__
-  `Custom
   batch <https://algolia.com/doc/api-reference/api-methods/batch/?language=python>`__

Settings
~~~~~~~~

-  `Get
   settings <https://algolia.com/doc/api-reference/api-methods/get-settings/?language=python>`__
-  `Set
   settings <https://algolia.com/doc/api-reference/api-methods/set-settings/?language=python>`__

Manage indices
~~~~~~~~~~~~~~

-  `List
   indexes <https://algolia.com/doc/api-reference/api-methods/list-indices/?language=python>`__
-  `Delete
   index <https://algolia.com/doc/api-reference/api-methods/delete-index/?language=python>`__
-  `Copy
   index <https://algolia.com/doc/api-reference/api-methods/copy-index/?language=python>`__
-  `Move
   index <https://algolia.com/doc/api-reference/api-methods/move-index/?language=python>`__
-  `Clear
   index <https://algolia.com/doc/api-reference/api-methods/clear-index/?language=python>`__

API Keys
~~~~~~~~

-  `Create secured API
   Key <https://algolia.com/doc/api-reference/api-methods/generate-secured-api-key/?language=python>`__
-  `Add API
   Key <https://algolia.com/doc/api-reference/api-methods/add-api-key/?language=python>`__
-  `Update API
   Key <https://algolia.com/doc/api-reference/api-methods/update-api-key/?language=python>`__
-  `Delete API
   Key <https://algolia.com/doc/api-reference/api-methods/delete-api-key/?language=python>`__
-  `Get API Key
   permissions <https://algolia.com/doc/api-reference/api-methods/get-api-key/?language=python>`__
-  `List API
   Keys <https://algolia.com/doc/api-reference/api-methods/list-api-keys/?language=python>`__

Synonyms
~~~~~~~~

-  `Save
   synonym <https://algolia.com/doc/api-reference/api-methods/save-synonym/?language=python>`__
-  `Batch
   synonyms <https://algolia.com/doc/api-reference/api-methods/batch-synonyms/?language=python>`__
-  `Delete
   synonym <https://algolia.com/doc/api-reference/api-methods/delete-synonym/?language=python>`__
-  `Clear all
   synonyms <https://algolia.com/doc/api-reference/api-methods/clear-synonyms/?language=python>`__
-  `Get
   synonym <https://algolia.com/doc/api-reference/api-methods/get-synonym/?language=python>`__
-  `Search
   synonyms <https://algolia.com/doc/api-reference/api-methods/search-synonyms/?language=python>`__
-  `Export
   Synonyms <https://algolia.com/doc/api-reference/api-methods/export-synonyms/?language=python>`__

Query rules
~~~~~~~~~~~

-  `Save a single
   rule <https://algolia.com/doc/api-reference/api-methods/rules-save/?language=python>`__
-  `Batch save multiple
   rules <https://algolia.com/doc/api-reference/api-methods/rules-save-batch/?language=python>`__
-  `Get a
   rule <https://algolia.com/doc/api-reference/api-methods/rules-get/?language=python>`__
-  `Delete a single
   rule <https://algolia.com/doc/api-reference/api-methods/rules-delete/?language=python>`__
-  `Clear all
   rules <https://algolia.com/doc/api-reference/api-methods/rules-clear/?language=python>`__
-  `Search for
   rules <https://algolia.com/doc/api-reference/api-methods/rules-search/?language=python>`__
-  `Export
   rules <https://algolia.com/doc/api-reference/api-methods/rules-export/?language=python>`__

A/B Test
~~~~~~~~

-  `Add an A/B
   test <https://algolia.com/doc/api-reference/api-methods/add-ab-test/?language=python>`__
-  `Get an A/B
   test <https://algolia.com/doc/api-reference/api-methods/get-ab-test/?language=python>`__
-  `List A/B
   tests <https://algolia.com/doc/api-reference/api-methods/get-ab-tests/?language=python>`__
-  `Stop an A/B
   test <https://algolia.com/doc/api-reference/api-methods/stop-ab-test/?language=python>`__
-  `Delete an A/B
   test <https://algolia.com/doc/api-reference/api-methods/delete-ab-test/?language=python>`__

MultiClusters
~~~~~~~~~~~~~

-  `Assign or Move
   userID <https://algolia.com/doc/api-reference/api-methods/assign-user-id/?language=python>`__
-  `Get top
   userID <https://algolia.com/doc/api-reference/api-methods/get-top-user-id/?language=python>`__
-  `Get
   userID <https://algolia.com/doc/api-reference/api-methods/get-user-id/?language=python>`__
-  `List
   clusters <https://algolia.com/doc/api-reference/api-methods/list-clusters/?language=python>`__
-  `List
   userIDs <https://algolia.com/doc/api-reference/api-methods/list-user-id/?language=python>`__
-  `Remove
   userID <https://algolia.com/doc/api-reference/api-methods/remove-user-id/?language=python>`__
-  `Search
   userID <https://algolia.com/doc/api-reference/api-methods/search-user-id/?language=python>`__

Advanced
~~~~~~~~

-  `Get
   logs <https://algolia.com/doc/api-reference/api-methods/get-logs/?language=python>`__
-  `Configuring
   timeouts <https://algolia.com/doc/api-reference/api-methods/configuring-timeouts/?language=python>`__
-  `Set extra
   header <https://algolia.com/doc/api-reference/api-methods/set-extra-header/?language=python>`__
-  `Wait for
   operations <https://algolia.com/doc/api-reference/api-methods/wait-task/?language=python>`__

Getting Help
------------

-  **Need help**? Ask a question to the `Algolia
   Community <https://discourse.algolia.com/>`__ or on `Stack
   Overflow <http://stackoverflow.com/questions/tagged/algolia>`__.
-  **Found a bug?** You can open a `GitHub
   issue <https://github.com/algolia/algoliasearch-client-python/issues>`__.


