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.
Website • autobotAI 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
Release history Release notifications | RSS feed
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.3.0.tar.gz
(5.9 kB
view details)
Built Distribution
jqqb-1.3.0-py3-none-any.whl
(6.4 kB
view details)
File details
Details for the file jqqb-1.3.0.tar.gz
.
File metadata
- Download URL: jqqb-1.3.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e52e82447291f08e5483fdc3fa8ec513f505124584a309046d482a17ed0e0c6 |
|
MD5 | 0e63717d09ba53f8807eac9eb0a48aae |
|
BLAKE2b-256 | 64539dad9ffd55c77826ce5c731c258da2c75a814fdccf53a0f0b141c9cc0e93 |
File details
Details for the file jqqb-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: jqqb-1.3.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7213bcd1f034a865dd235173d2e7f4d4f8c14a0271cb96809ac45d7dfd59ce5f |
|
MD5 | 4cc755eb8ec6752adcc4082ed009a4d7 |
|
BLAKE2b-256 | 47f9ec2b539f403e1551fcd45a224d0fdce0b7b7f7ffed9fd25c37f499deff29 |