Import the module:

>>> import pyes

pyes is able to use standard http or thrift protocol. If your port starts with “92” http protocol is used, otherwise thrift.

For a single connection (which is _not_ thread-safe), pass a list of servers.

For thrift:

>>> conn = pyes.ES() # Defaults to connecting to the server at ''
>>> conn = pyes.ES([''])
>>> conn = pyes.ES(("thrift", "", "9500"))
>>> conn = pyes.ES([("thrift", "", "9500"), ("thrift", "", "9500"),])

For http:

>>> conn = pyes.ES([''])
>>> conn = pyes.ES(("http", "","9200"))
>>> conn = pyes.ES([("thrift", "", "9200"), ("thrift", "", "8000"),])

Connections are robust to server failures. Upon a disconnection, it will attempt to connect to each server in the list in turn. If no server is available, it will raise a NoServerAvailable exception.

Timeouts are also supported and should be used in production to prevent a thread from freezing while waiting for the server to return.

>>> conn = pyes.ES(timeout=3.5) # 3.5 second timeout
(Make some pyes calls and the connection to the server suddenly becomes unresponsive.)

Traceback (most recent call last):

Note that this only handles socket timeouts.