Skip to main content

Library to help developer to create filter for the sqlachemy orm.

Project description

Introduction

Filter sqlalchemy query with json data.

This is an early stage version of the project a lot of change is coming.

Installation

pip install sqla-filter

Getting Started

Create an instance of the JSONFilterParser with the json string.

Example:

# Sqlalchemy setup ... + model definition

# Create a JSON parser instance
parser = JSONFiltersParser(raw_json_string)

# you now have a tree available as a property in the parser
print(parser.tree)

# You can finaly filter your query
query = session.query(Post)
filtered_query = parser.tree.filter(query)

# Get the results
query.all()

Operators

The following operators are or will be implemented:

support operators name code
[ ] like like like()
[x] eq equal operators.eq
[x] not_eq not equal operators.ne
[x] null null is None
[x] not_null not null is not None
[x] gt greater than operators.gt
[x] gte greater than or equal operators.ge
[x] lt lower than operators.lt
[x] lte lower than or equal operators.le
[x] in in in_()
[x] not_in not in ~.in_()
[ ] contains contains operators.contains

Formats

JSON

{
    "type": "and",
    "data": [
        {
            "type": "or",
            "data": [
                {
                    "type": "operator",
                    "data": {
                        "attribute": "name",
                        "operator": "eq",
                        "value": "toto"
                    }
                },
                {
                    "type": "operator",
                    "data":{
                        "attribute": "name",
                        "operator": "eq",
                        "value": "tata"
                    }
                }
            ]
        },
        {
            "type": "operator",
            "data": {
                "attribute": "age",
                "operator": "eq",
                "value": 21
            }
        }
    ]
}

/!\ Json format can change in the futur. /!\

Tree result

                                      +----------------------+
                                      |                      |
                                      |          and         |
                                      |                      |
                                      -----------------------+
                                                 ||
                                                 ||
                                                 ||
                    +----------------------+     ||     +----------------------+
                    |                      |     ||     |                      |
                    |          or          <------------>      age == 21       |
                    |                      |            |                      |
                    +----------------------+            +----------------------+
                               ||
                               ||
                               ||
+----------------------+       ||       +----------------------+
|                      |       ||       |                      |
|     name == toto     <---------------->     name == tata     |
|                      |                |                      |
+----------------------+                +----------------------+

Contribute

Fork the repository and run the following command to install the dependencies and the dev dependencies.

pip install -e '.[dev]'

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

sqla-filters-0.0.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

sqla_filters-0.0.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file sqla-filters-0.0.1.tar.gz.

File metadata

  • Download URL: sqla-filters-0.0.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6

File hashes

Hashes for sqla-filters-0.0.1.tar.gz
Algorithm Hash digest
SHA256 aef321e080a0d09c6f798210a09fd51088121b6afc8dee9d824ab6ba74264715
MD5 01623cddc5a55b6e02767aefa13d31f9
BLAKE2b-256 43816802becd43698ce37ad54396479d7214e7c1dd819148390ed03cff011cf7

See more details on using hashes here.

File details

Details for the file sqla_filters-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sqla_filters-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6

File hashes

Hashes for sqla_filters-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 507822568b7d2c71f7faaea6988f1263c6c03a6ed63313fa8dff0a73b103b0ef
MD5 9e8d6772051e3f14cb4acf97e952e987
BLAKE2b-256 68b472d02f3ad21a24a8fbf3fe51d16847ff505806dbbdfc1506e10c06fbf926

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