Skip to main content

Python RQL

pyversions PyPi Status PyPI status PyPI Downloads Quality Gate Status Coverage

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.

RQL Reference

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.

  1. Values with whitespaces or special characters, like ',' need to have "" or ''
  2. Supported date format is ISO8601: 2019-02-12
  3. Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00

Supported operators

  1. Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
  2. List (in, out)
  3. Logical (and, or, not)
  4. Constants (null(), empty())
  5. Ordering (ordering)
  6. Select (select)
  7. 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

  1. Python 3.6+
  2. Install dependencies pip install poetry && poetry install

Testing

  1. Python 3.6+
  2. 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 results
  • coverage.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.

Release files for lib-rql 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lib-rql 1.1.1
File Size Uploaded
lib-rql-1.1.1.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lib-rql 1.1.1
File Interpreter ABI Platform
lib_rql-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / lib-rql-1.1.1.tar.gz

Download URL lib-rql-1.1.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
69f17bc749770f519f9a51752e92a91518a83c40012a545d9e54cca133fca8e2
BLAKE2b-256 checksum
How to use checksums
a22f58543e3505a6cb5eb88741eb1c7b9b147ea5a61e3e36a81318e7f237fddd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.11.0-1028-azure

Release files / lib_rql-1.1.1-py3-none-any.whl

Download URL lib_rql-1.1.1-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aee3ace3ebeb0bae674871a0584df6229e2eb28e55b2c264360b907c2fd1892d
BLAKE2b-256 checksum
How to use checksums
dc62ca0f155f3d6601e10eb8d3f2b588f2ce76f61fff2ca70dad06daa228ad96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.12 Linux/5.11.0-1028-azure

Release history Release notifications | RSS feed

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page