Skip to main content

Python client for Elasticsearch built on top of elasticsearch-dsl

Project description

fiqs

Build Status

fiqs is an opinionated high-level library whose goal is to help you write concise queries agains Elasticsearch and better consume the results. It is built on top of the awesome Elasticsearch DSL library.

fiqs exposes a flatten_result function which transforms an elasticsearch-dsl Result, or a dictionary, into the list of its nodes. fiqs also lets you create Model classes, a la Django, which automatically generates an Elasticsearch mapping. Finally fiqs exposes a FQuery objects which, leveraging your models, lets you write less verbose queries against Elasticsearch.

Compatibility

fiqs is compatible with Elasticsearch 6.X and works with Python3

Documentation

Documentation is available at https://fiqs.readthedocs.io/

Code example

You define a model, matching what is in your Elasticsearch cluster:

    from fiqs import models

    class Sale(models.Model):
        index = 'sale_data'
        doc_type = 'sale'

        id = fields.IntegerField()
        shop_id = fields.IntegerField()
        client_id = fields.KeywordField()

        timestamp = fields.DateField()
        price = fields.IntegerField()
        payment_type = fields.KeywordField(choices=['wire_transfer', 'cash', 'store_credit'])

You can then write clean queries:

    from elasticsearch_dsl import Search
    from fiqs.aggregations import Sum
    from fiqs.query import FQuery

    from .models import Sale

    search = Search(...)
    metric = FQuery(search).values(
        total_sales=Sum(Sale.price),
    ).group_by(
        Sale.shop_id,
        Sale.client_id,
    )
    result = metric.eval()

And let fiqs organise the results:

    print(result)
    # [
    #     {
    #         "shop_id": 1,
    #         "client_id": 1,
    #         "doc_count": 30,
    #         "total_sales": 12345.0,
    #     },
    #     {
    #         "shop_id": 2,
    #         "client_id": 1,
    #         "doc_count": 20,
    #         "total_sales": 23456.0,
    #     },
    #     {
    #         "shop_id": 3,
    #         "client_id": 1,
    #         "doc_count": 10,
    #         "total_sales": 34567.0,
    #     },
    #     [...]
    # ]

Contributing

The fiqs project is hosted on Github

To run the tests on your machine use this command: python setup.py test Some tests are used to generate results output from Elasticsearch. To run them you will need to run a docker container on your machine: docker run -d -p 8200:9200 -p 8300:9300 elasticsearch:6.x.x and then run pytest -k docker.

License

See attached LICENSE file.

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

fiqs-0.4.0.tar.gz (32.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: fiqs-0.4.0.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

File hashes

Hashes for fiqs-0.4.0.tar.gz
Algorithm Hash digest
SHA256 bf79b4043e6e3ebfc4eab1163e2b2fa2d3b0927cb8c32e5eb4d36f6fdea309fe
MD5 77c12ff45e6740b51572cdd9fe1edc40
BLAKE2b-256 ae6985bd32d90722db910300187081f7dc26dca7d1ec6093b610354742ad3716

See more details on using hashes here.

Supported by

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