Skip to main content

Sqla-filters-json

Add json parser to the sqla-filters package.

Introduction

This package

Installation

pip install sqla-filter-json

Getting Started

JSON format

{
    "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
            }
        }
    ]
}

:warning: Json format can change in the futur. :warning:

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()

Result tree

                                      +----------------------+
                                      |                      |
                                      |          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]'

Metadata

Release files for sqla-filters-json 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqla-filters-json 0.0.1
File Size Uploaded
sqla-filters-json-0.0.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqla-filters-json 0.0.1
File Interpreter ABI Platform
sqla_filters_json-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / sqla-filters-json-0.0.1.tar.gz

Download URL sqla-filters-json-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
77bd2ba08e53b9c2960744a1665f48c7174313ac164dea2538241d739532834e
BLAKE2b-256 checksum
How to use checksums
2dfb3ecf01ce086551c59ce0975b57d5bd08fada267229b30d3cac887b1b13dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

Release files / sqla_filters_json-0.0.1-py3-none-any.whl

Download URL sqla_filters_json-0.0.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f463fa0f5044ada29a811d55c5d10687824e6c1e5dddbfc11de02d6f0cf617a
BLAKE2b-256 checksum
How to use checksums
0237e83e5430d01c511c332d42d0b638e1da2cecf1e0bc7ed8855dae477321fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page