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([''])

For http:

>>> conn = pyes.ES([''])

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.

Previous topic


Next topic


This Page