Skip to content

infinilabs/easysearch-py

Repository files navigation

Python Easysearch Client

Note

This library is derived from 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:

$ python -m pip install easysearch

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

$ python -m pip install easysearch[async]

Read more about how to use asyncio with this project.

Compatibility

The library is compatible with Easysearch 1.x and 2.x versions.

For Easysearch 1.x, use the major version 1 (1.x.y) of the library.

For Easysearch 2.x, use the major version 2 (2.x.y) of the library.

The recommended way to set your requirements in your setup.py or requirements.txt is:

# Easysearch 2.x
easysearch>=2.0.0,<3.0.0

# Easysearch 1.x
easysearch>=1.0.0,<2.0.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.

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.

About

Python client for Easysearch

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages