Giter VIP home page Giter VIP logo

lib-rql's Introduction

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.8+
  2. Install dependencies pip install poetry && poetry install

Testing

  1. Python 3.8+
  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.

lib-rql's People

Contributors

maxipavlovic avatar gab832 avatar ffaraone avatar marcserrat avatar zzzevaka avatar d3rky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.