skip to navigation
skip to content

Not Logged In

SlimES 0.0.2

Thin Python connector for Elasticsearch.

Thin Python client for Elasticsearch

This is a little wrapper over the requests module that helps you do your thing with Elasticsearch. But not too much. For each request, you need to specify the following, where they are applicable:

  • desired request method
  • index, type, ID
  • "suffix" (which might be the _search, _bulk, etc at the end of the URL)
  • a dictionary or a string with the data you want to submit

Why would I want that?

Two reasons:

  • flexibility - the point of this client is to keep up with the many features constantly added to Elasticsearch. You can customize your index operations and queries as much as you need
  • documentation - once you get the hang of the few options particular to this client, you only have to look at the documentation on Elasticsearch itself to access its features

If this is not what you want, I would suggest to look at pyes or pyelasticsearch

Features and usage

There are a few files in there at the moment:

  • slimes.py - the module itself
  • tests_slimes.py - unit tests

Here are the main features:

Converts your dict to JSON (you can disable that for stuff like bulks)

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200"])
#define the document
testdoc = {"foo": 2345, "bar": True}
#post the document
my_requester.request(method="post",
    myindex="testindex",
    mytype="testtype",
    mydata=testdoc)

Can get a list of nodes, for redundancy

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200","my_other_server:9200"])

Loads the JSON results for you

If something goes wrong (eg: non 2XX status code), you'll get an exception. Otherwise, you'll get a dictionary with the results from ES:

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200"])
myquery = {\
    "query": {\
            "term": {\
                    "age": 28\
            }\
    }\
}
results = my_requester.request(method="post",
    myindex="testindex",
    mytype="testtype",
    mysuffix="_search",
    mydata=myquery)
print "Number of hits is %d" % result['hits']['total']

Can receive parameters at will

So you can index with the "create" parameter, like this:

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200"])
testdoc={"foo": "bar"}
my_requester.request(method="put",
    myindex="testindex",
    mytype="testtype",
    myID=1,
    mysuffix="?op_type=create",
    mydata=testdoc)

Or, you can put the parameter(s) as a dictionary:

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200"])
testdoc={"foo": "bar"}
my_requester.request(method="put",
    myindex="testindex",
    mytype="testtype",
    myID=1,
    myparams={"op_type":"create"},
    mydata=testdoc)

And you can also specify a timeout:

#!/usr/bin/env python
import slimes
my_requester = slimes.Requester(["localhost:9200"])
#give it 10 seconds to complete, otherwise give Exception
my_requester.request(mytimeout=10)

TODOes

Enhancements will be about the transport. Stuff like: - use thrift - get all cluster nodes

Stay tuned :)

Bugs

Please feel free to report them on github

 
File Type Py Version Uploaded on Size
SlimES-0.0.2.tar.gz (md5) Source 2012-09-10 4KB
  • Downloads (All Versions):
  • 9 downloads in the last day
  • 43 downloads in the last week
  • 245 downloads in the last month