Python RQL Filtering
Project description
Python RQL
Introduction
RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax. This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.
Install
Python RQL
can be installed from pypi.org using pip:
$ pip install lib-rql
Documentation
Python RQL
documentation is hosted on the Read the Docs service.
Projects using Python RQL
Django RQL
is the Django app, that adds RQL filtering to your application.
Visit the Django RQL project repository for more informations.
Notes
Parsing is done with Lark (cheatsheet). The current parsing algorithm is LALR(1) with standard lexer.
- Values with whitespaces or special characters, like ',' need to have "" or ''
- Supported date format is ISO8601: 2019-02-12
- Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
Supported operators
- Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
- List (in, out)
- Logical (and, or, not)
- Constants (null(), empty())
- Ordering (ordering)
- Select (select)
- Tuple (t)
Examples
Parsing a RQL query
from py_rql import parse
from py_rql.exceptions import RQLFilterError
try:
tree = parse('eq(key,value)')
except RQLFilterError:
pass
Filter a list of dictionaries
from py_rql.constants import FilterTypes
from py_rql.filter_cls import FilterClass
class BookFilter(FilterClass):
FILTERS = [
{
'filter': 'title',
},
{
'filter': 'author.name',
},
{
'filter': 'status',
},
{
'filter': 'pages',
'type': FilterTypes.INT,
},
{
'filter': 'featured',
'type': FilterTypes.BOOLEAN,
},
{
'filter': 'publish_date',
'type': FilterTypes.DATETIME,
},
]
filters = BookFilter()
query = 'eq(title,Practical Modern JavaScript)'
results = list(filters.filter(query, DATA))
print(results)
query = 'or(eq(pages,472),lt(pages,400))'
results = list(filters.filter(query, DATA))
print(results)
Development
- Python 3.8+
- Install dependencies
pip install poetry && poetry install
Testing
- Python 3.8+
- Install dependencies
pip install poetry && poetry install
Check code style: poetry run flake8
Run tests: poetry run pytest
Tests reports are generated in tests/reports
.
out.xml
- JUnit test resultscoverage.xml
- Coverage xml results
To generate HTML coverage reports use:
--cov-report html:tests/reports/cov_html
License
Python RQL
is released under the Apache License Version 2.0.
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
Built Distribution
File details
Details for the file lib_rql-2.0.2.tar.gz
.
File metadata
- Download URL: lib_rql-2.0.2.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c7edfa6f822ff6397181a1d99d71e0dc7273ed2655bd3193c021049c40f726c |
|
MD5 | 9eae9edee1a49b6a9c515322b4ae8ade |
|
BLAKE2b-256 | 31d56facc0028c6a27f228999cf4990b4b3d1a31b501153e415b7b9b31d24a0a |
File details
Details for the file lib_rql-2.0.2-py3-none-any.whl
.
File metadata
- Download URL: lib_rql-2.0.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.8.18 Linux/6.5.0-1023-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f30cda8e53e269ae2ea6c93f6009b1dc127fcf3aee5027b99de314aa0bbaa7f |
|
MD5 | b80b1ad51df5ef7df8531c0994e9370a |
|
BLAKE2b-256 | 8e5bc9b11c88114cac3b611f8b5b938aa04d581e95ddc708c56f70d378bda263 |