1- Python RQL
2- ==========
1+ # Python RQL
2+
3+
34[ ![ pyversions] ( https://img.shields.io/pypi/pyversions/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
45[ ![ PyPi Status] ( https://img.shields.io/pypi/v/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
56[ ![ PyPI status] ( https://img.shields.io/pypi/status/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
7+ [ ![ PyPI Downloads] ( https://img.shields.io/pypi/dm/lib-rql )] ( https://pypi.org/project/lib-rql/ )
68[ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=alert_status )] ( https://sonarcloud.io/summary/new_code?id=lib-rql )
79[ ![ Coverage] ( https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=coverage )] ( https://sonarcloud.io/summary/new_code?id=lib-rql )
810
9- RQL
10- ---
11+
12+
13+ ## Introduction
1114
1215RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax.
1316This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.
1417
1518[ RQL Reference] ( https://connect.cloudblue.com/community/api/rql/ )
1619
17- Notes
18- -----
20+ ## Install
21+
22+ ` Python RQL ` can be installed from [ pypi.org] ( https://pypi.org/project/lib-rql/ ) using pip:
23+
24+ ```
25+ $ pip install lib-rql
26+ ```
27+
28+ ## Documentation
29+
30+ [ ` Python RQL ` documentation] ( https://lib-rql.readthedocs.io/en/latest/ ) is hosted on the _ Read the Docs_ service.
31+
32+
33+ ## Projects using Python RQL
34+
35+ ` Django RQL ` is the Django app, that adds RQL filtering to your application.
36+
37+ Visit the [ Django RQL] ( https://github.com/cloudblue/django-rql ) project repository for more informations.
38+
39+
40+ ## Notes
1941
2042Parsing is done with [ Lark] ( https://github.com/lark-parser/lark ) ([ cheatsheet] ( https://lark-parser.readthedocs.io/en/latest/lark_cheatsheet.pdf ) ).
2143The current parsing algorithm is [ LALR(1)] ( https://www.wikiwand.com/en/LALR_parser ) with standard lexer.
2244
23- Supported operators
24- =============================
45+ 0 . Values with whitespaces or special characters, like ',' need to have "" or ''
46+ 1 . Supported date format is ISO8601: 2019-02-12
47+ 2 . Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
48+
49+
50+ ## Supported operators
51+
25521 . Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
26532 . List (in, out)
27543 . Logical (and, or, not)
@@ -31,8 +58,11 @@ Supported operators
31587 . Tuple (t)
3259
3360
34- Example
35- =======
61+ ## Examples
62+
63+ ### Parsing a RQL query
64+
65+
3666``` python
3767from py_rql import parse
3868from py_rql.exceptions import RQLFilterError
@@ -43,27 +73,66 @@ except RQLFilterError:
4373 pass
4474```
4575
46- Notes
47- =====
48- 0 . Values with whitespaces or special characters, like ',' need to have "" or ''
49- 1 . Supported date format is ISO8601: 2019-02-12
50- 2 . Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
76+
77+ ### Filter a list of dictionaries
78+
79+ ``` python
80+ from py_rql.constants import FilterTypes
81+ from py_rql.filter_cls import FilterClass
82+
83+
84+ class BookFilter (FilterClass ):
85+ FILTERS = [
86+ {
87+ ' filter' : ' title' ,
88+ },
89+ {
90+ ' filter' : ' author.name' ,
91+ },
92+ {
93+ ' filter' : ' status' ,
94+ },
95+ {
96+ ' filter' : ' pages' ,
97+ ' type' : FilterTypes.INT ,
98+ },
99+ {
100+ ' filter' : ' featured' ,
101+ ' type' : FilterTypes.BOOLEAN ,
102+ },
103+ {
104+ ' filter' : ' publish_date' ,
105+ ' type' : FilterTypes.DATETIME ,
106+ },
107+ ]
108+
109+ filters = BookFilter()
110+
111+ query = ' eq(title,Practical Modern JavaScript)'
112+ results = list (filters.filter(query, DATA ))
113+
114+ print (results)
115+
116+ query = ' or(eq(pages,472),lt(pages,400))'
117+ results = list (filters.filter(query, DATA ))
118+
119+ print (results)
120+ ```
51121
52122
53- Development
54- ===========
123+ ## Development
124+
55125
561261 . Python 3.6+
57- 0 . Install dependencies ` requirements/dev.txt `
127+ 0 . Install dependencies ` pip install poetry && poetry install `
58128
59- Testing
60- =======
129+ ## Testing
61130
621311 . Python 3.6+
63- 0 . Install dependencies ` requirements/test.txt `
132+ 0 . Install dependencies ` pip install poetry && poetry install `
64133
65- Check code style: ` flake8 `
66- Run tests: ` pytest `
134+ Check code style: ` poetry run flake8`
135+ Run tests: ` poetry run pytest`
67136
68137Tests reports are generated in ` tests/reports ` .
69138* ` out.xml ` - JUnit test results
@@ -72,3 +141,6 @@ Tests reports are generated in `tests/reports`.
72141To generate HTML coverage reports use:
73142` --cov-report html:tests/reports/cov_html `
74143
144+ ## License
145+
146+ ` Python RQL ` is released under the [ Apache License Version 2.0] ( https://www.apache.org/licenses/LICENSE-2.0 ) .
0 commit comments