While “auditioning” for Sematext, I’ve done this Python client for Elasticsearch called slimES. Like the name suggests, it’s a very thin client, and I’ve used it for taking care of the repeating stuff in my code. For example, encoding a dictionary in JSON. At the same time, I could continue throwing whatever HTTP request I needed to my Elasticsearch nodes.
If you like your software to be simple and straightforward, you might find slimES useful, too. You can find it on GitHub, or on PyPI.
Please tweet about slimES – The Slimmest Python Client for Elasticsearch
How can you use it?
First, you need to install it:
% pip install slimes
Then you have to create a Requester object and start throwing requests at Elasticsearch. For example, to post a new document:
>>> import slimes >>> my_requester = slimes.Requester(["localhost:9200"]) >>> testdoc = {"foo": 2345, "bar": True} >>> my_requester.request(method="post", ... myindex="testindex", ... mytype="testtype", ... mydata=testdoc) {u'_type': u'testtype', u'_id': u'vwJ7fljtSz-YAxiIKzYXmw', u'ok': True, u'_version': 1, u'_index': u'testindex'}
To get it:
>>> my_requester.request(method="get", ... myindex="testindex", ... mytype="testtype", ... myID="vwJ7fljtSz-YAxiIKzYXmw") {u'_type': u'testtype', u'exists': True, u'_source': {u'foo': 2345, u'bar': True}, u'_index': u'testindex', u'_version': 1, u'_id': u'vwJ7fljtSz-YAxiIKzYXmw'}
For more examples, check out the GitHub Readme and the integration tests. All in all, there are really just a few parameters:
- method: HTTP method (get, post, delete…)
- myindex/mytype/myID: index/type/ID name, if it’s applicable
- mysuffix/myparams: optional parameters which you can supply as strings (mysuffix) or dictionary (myparams)
- mydata: the HTTP payload. For most requests, it would be a JSON, so you can supply a dictionary and it will be encoded for you. If you don’t want that, add jsonnize=False
- mytimeout: optional timeout for the request
Why would you use it?
- it’s transparent: it only hides the bits you probably do all the time, like building the URL and encoding your dictionary in JSON, and leaves you the power to dig the Elasticsearch documentation and make up whatever HTTP request you want
- it’s tiny and well tested: you can probably print the running code on a sheet of paper (maybe you’ll need duplex printing for that), so if you like straightforward stuff, this client is for you. Whatever doesn’t fit on that sheet of paper is either documentation, unit tests or integration tests
If you like your software simple, I’d suggest you give it a spin. If you don’t like it for any reason, please open an issue. Happy coding
