Skip to main content

Python parsing, evaluation and inspection tools for jQuery-QueryBuilder rules

Project description

jQueryQueryBuilder

Python Rule evaluator for jQuery-QueryBuilder. It evaluates rules agains provided objects.

WebsiteautobotAI Cloud Governance

Inspired from SixiS/jquery_query_builder-rails

Usage

Install the package.

pip install jqqb

Usage Example:

from jqqb import QueryBuilder
rule_json = {
    "condition": "AND",
    "rules": [{
        "id": "tagname",
        "field": "tags.name",
        "type": "string",
        "input": "text",
        "operator": "not_contains",
        "value": "production"
    }, {
        "id": "tagname",
        "field": "tags.name",
        "type": "string",
        "input": "text",
        "operator": "begins_with",
        "value": "development"
    }, {
        "condition": "OR",
        "rules": [{
            "id": "type",
            "field": "type",
            "type": "string",
            "input": "text",
            "operator": "equal",
            "value": "ec2"
        },{
            "id": "type",
            "field": "type",
            "type": "string",
            "input": "text",
            "operator": "equal",
            "value": "ami"
        }]
    }]
}


evaluator = QueryBuilder(rule_json)
object_1 = {'type': "ec2", "tags": [{"name": "hello"}, {"name": "asdfasfproduction_instance"}]}
object_2 = {'type': "ami", "tags": [{"name": "development"}, {"name": "asfdafdroduction_instance"}, {"name": "proction"}]}
objects = [object_1, object_2]

print(evaluator.match_objects(objects))
print(evaluator.inspect_objects(objects))

Result:

[{'type': 'ami', 'tags': [{'name': 'development'}, {'name': 'asfdafdroduction_instance'}, {'name': 'proction'}]}]

[
    {
        'object': {'type': 'ec2', 'tags': [{'name': 'hello'}, {'name': 'asdfasfproduction_instance'}]},
        'selected': False,
        'results': [
            (
                {'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'not_contains', 'value': 'production'},
                (['hello', 'asdfasfproduction_instance'], 'production', False)
            ),
            (
                {'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'begins_with', 'value': 'development'},
                (['hello', 'asdfasfproduction_instance'], 'development', False)
            ),
            (
                {
                    'condition': 'OR',
                    'rules': [
                        {
                            'id': 'type',
                            'field': 'type',
                            'type': 'string',
                            'input': 'text',
                            'operator': 'equal',
                            'value': 'ec2'
                        }, {
                            'id': 'type',
                            'field': 'type',
                            'type': 'string',
                            'input': 'text',
                            'operator': 'equal',
                            'value': 'ami'
                        }
                    ]
                },
                [
                    (
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
                        ('ec2', 'ec2', True)
                    ),
                    (
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'},
                        ('ec2', 'ami', False)
                    )
                ]
            )
        ]
    },
    {
        'object': {'type': 'ami', 'tags': [{'name': 'development'}, {'name': 'asfdafdroduction_instance'}, {'name': 'proction'}]},
        'selected': True,
        'results': [
            (
                {'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'not_contains', 'value': 'production'},
                (
                    ['development', 'asfdafdroduction_instance', 'proction'], 'production', True
                )
            ), (
                {'id': 'tagname', 'field': 'tags.name', 'type': 'string', 'input': 'text', 'operator': 'begins_with', 'value': 'development'},
                (
                    ['development', 'asfdafdroduction_instance', 'proction'], 'development', True
                )
            ), (
                {
                    'condition': 'OR',
                    'rules': [
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'}
                    ]
                }, [
                    (
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ec2'},
                        ('ami', 'ec2', False)
                    ), (
                        {'id': 'type', 'field': 'type', 'type': 'string', 'input': 'text', 'operator': 'equal', 'value': 'ami'},
                        ('ami', 'ami', True)
                    )
                ]
            )
        ]
    }
]

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

jqqb-1.5.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

jqqb-1.5.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file jqqb-1.5.0.tar.gz.

File metadata

  • Download URL: jqqb-1.5.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for jqqb-1.5.0.tar.gz
Algorithm Hash digest
SHA256 a5aeb9f171749a1b9cb1ea2cefdb051e4dccf2056a9589086a5ca25cbb2f7c7b
MD5 188a63bf4ca82a8bd7caba57ded4ca39
BLAKE2b-256 38117d47baac94ef8e75db3b4b66e3100c3b3ae77089d823b6a3134ca72b7e3c

See more details on using hashes here.

File details

Details for the file jqqb-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: jqqb-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for jqqb-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3891303f3d418ccbbd57b3a9f5f212d5daafefdc3181eb96ee1aba9303afe329
MD5 17d85b179a948c919501a285575ab349
BLAKE2b-256 220ab3783d4e8b89d655f9e16493c2437281c043dab9be4f94da23dc1b10f8ff

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