Python Easysearch Client
=========================

.. note::
    This library is derived from `elasticsearch-py <https://github.com/elastic/elasticsearch-py>`_ 7.10.1,
    Copyright 2013-2020 Elasticsearch B.V., and is now maintained by INFINI Labs.

Official Python client for INFINI Easysearch. Its goal is to provide common
ground for all Easysearch-related code in Python; because of this it tries
to be opinion-free and very extendable.


Installation
------------

Install the ``easysearch`` package with pip::

    $ pip install easysearch

If your application uses async/await in Python you can install with
the ``async`` extra::

    $ pip install "easysearch[async]"

Alternatively, you can download and install the latest version directly from the `GitHub Releases <https://github.com/infinilabs/easysearch-py/releases>`_ page.


Compatibility
-------------

The library is currently in the ``0.x`` release series and is compatible with INFINI Easysearch. 

The recommended way to set your requirements in your ``setup.py`` or
``requirements.txt`` is to pin the version to ensure stability. For example::

    easysearch>=0.1.0


Example use
-----------

Simple use-case::

    >>> from datetime import datetime
    >>> from easysearch import Easysearch

    # by default we connect to localhost:9200
    >>> es = Easysearch()

    # create an index in easysearch, ignore status code 400 (index already exists)
    >>> es.indices.create(index='my-index', ignore=400)
    {'acknowledged': True, 'shards_acknowledged': True, 'index': 'my-index'}

    # datetimes will be serialized
    >>> es.index(index="my-index", id=42, body={"any": "data", "timestamp": datetime.now()})
    {'_index': 'my-index',
     '_type': '_doc',
     '_id': '42',
     '_version': 1,
     'result': 'created',
     '_shards': {'total': 2, 'successful': 1, 'failed': 0},
     '_seq_no': 0,
     '_primary_term': 1}

    # but not deserialized
    >>> es.get(index="my-index", id=42)['_source']
    {'any': 'data', 'timestamp': '2019-05-17T17:28:10.329598'}

`Full documentation`_.

.. _Full documentation: https://github.com/infinilabs/easysearch-py

Using SSL Context with a self-signed cert use-case::

    >>> from easysearch import Easysearch
    >>> from ssl import create_default_context

    >>> context = create_default_context(cafile="path/to/cafile.pem")
    >>> es = Easysearch("https://easysearch.url:port", ssl_context=context, http_auth=('admin','password'))
    >>> es.info()


Features
--------

The client's features include:

 * translating basic Python data types to and from json (datetimes are not
   decoded for performance reasons)
 * configurable automatic discovery of cluster nodes
 * persistent connections
 * load balancing (with pluggable selection strategy) across all available nodes
 * failed connection penalization (time based - failed connections won't be
   retried until a timeout is reached)
 * support for ssl and http authentication
 * thread safety
 * pluggable architecture


License
-------

Copyright 2021-2026 INFINI Labs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.