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)
)
]
)
]
}
]
Metadata
Release files for jqqb 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jqqb-1.5.0.tar.gz | 6.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jqqb-1.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.5 kB
Release files / jqqb-1.5.0.tar.gz
| Download URL | jqqb-1.5.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5aeb9f171749a1b9cb1ea2cefdb051e4dccf2056a9589086a5ca25cbb2f7c7b
|
|
BLAKE2b-256 checksum How to use checksums |
38117d47baac94ef8e75db3b4b66e3100c3b3ae77089d823b6a3134ca72b7e3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / jqqb-1.5.0-py3-none-any.whl
| Download URL | jqqb-1.5.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3891303f3d418ccbbd57b3a9f5f212d5daafefdc3181eb96ee1aba9303afe329
|
|
BLAKE2b-256 checksum How to use checksums |
220ab3783d4e8b89d655f9e16493c2437281c043dab9be4f94da23dc1b10f8ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|