Skip to main content

Extends the official Elasticsearch Python API adding Tornado AsyncHTTPClient support

Project description

Extends the official Elasticsearch Python API adding Tornado AsyncHTTPClient support.

Version Downloads License

Installation

tornado_elasticsearch is available on the Python Package Index and can be installed using pip or easy_install:

pip install tornado_elasticsearch

Example Request Handlers

from tornado import gen
from tornado import web
from tornado_elasticsearch import AsyncElasticsearch
import uuid

class Example(web.RequestHandler):

    def initialize(self):
        self.es = AsyncElasticsearch()

    @web.asynchronous
    @gen.engine
    def delete(self, *args, **kwargs):
        result = yield self.es.delete(index='test-index', doc_type='tweet',
                                      id=self.get_argument('id'))
        self.finish(result)

    @web.asynchronous
    @gen.engine
    def get(self, *args, **kwargs):
        if self.get_argument('id', None):
            result = yield self.es.get(index='test-index', doc_type='tweet',
                                       id=self.get_argument('id'))
        else:
            result = yield self.es.search(index='test-index')
        self.finish(result)

    @web.asynchronous
    @gen.engine
    def post(self, *args, **kwargs):
        doc = {
            'author': self.get_current_user() or 'Unknown',
            'text': self.get_argument('text'),
            'timestamp': datetime.datetime.now()
        }
        result = yield self.es.index(index='test-index',
                                     doc_type='tweet',
                                     body=doc,
                                     id=str(uuid.uuid4()))
        self.finish(result)


class Info(web.RequestHandler):

    @web.asynchronous
    @gen.engine
    def get(self, *args, **kwargs):
        es = AsyncElasticsearch()
        info = yield es.info()
        self.finish(info)

Version History

  • 0.3.0: Bugfix: Add body to log_request_fail call (#1)

  • 0.2.0: Bugfix: force method to POST if GET and body passed

  • 0.1.0: Initial version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tornado_elasticsearch-0.4.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tornado_elasticsearch-0.4.0-py2-none-any.whl (11.8 kB view details)

Uploaded Python 2

File details

Details for the file tornado_elasticsearch-0.4.0.tar.gz.

File metadata

File hashes

Hashes for tornado_elasticsearch-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0fe2683f5bc15a7a4c92c60bca9957a6231abf4929984ec29f9e6faad62ff783
MD5 3850d887983729cf2c5b3d1e76eb4a75
BLAKE2b-256 ef01a67f9a614ec9a400d94a60907ec4fd2b8d764d1ccf510318dd6852e74cce

See more details on using hashes here.

File details

Details for the file tornado_elasticsearch-0.4.0-py2-none-any.whl.

File metadata

File hashes

Hashes for tornado_elasticsearch-0.4.0-py2-none-any.whl
Algorithm Hash digest
SHA256 2b578cf087e6e237ac8d153a0f50fecf2bba2ef9c680d7c1b2bd0d338878b1f8
MD5 13d98cc5a75ce040ad9c4976ce692e16
BLAKE2b-256 6bb45db22b971f5335b3e3936787ed40ba5a509491d83991e2e829e673090fa9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page