WherEval
Tool for parsing SQL like where expressions and evaluating against live data
Installation
python3 -m pip install whereval
Inspiration
This tool will scratch an itch I've had for some cli tools where I want to pass complex filter expressions to control output / processing.
For instance with my histstat fork, I would like to have better filtering of networking information to be output to sqlite. See: https://github.com/JavaScriptDude/histstat
Another usecase for this is a tool I've wanted to write where I can write a tail -f wrapper in python where I can define a filter in cli parameters to limit output to the console. Have not written this yet but its on my todo now that I've got this API.
API Example
(Ex1) Basic Concept:
from datetime import date
from whereval import Where, util as wutil
print("\n(Ex1) Basic Idea")
sw = wutil.StopWatch()
# Where query (terse example)
qry = "(f0>=2+f1=1+f2='s')|(f3~'foo%')"
# Field and type spec
spec = {'f0': int,'f1': bool,'f2': str,'f3': str, 'f4': dt_date}
# Instantiate Where
# - Parses query and uses data to form rules for data types and fields
wher = Where(query=qry, spec=spec)
print(f"Query:\n . raw:\t{qry}\n . compiled: {wher}\n\nTests:")
def _print(wher, data, tup):
(ok, result, issues) = tup
if not ok:
print(f"Eval failed for {wher}. Issues: {issues}")
else:
print(f"\t{result}\tw/ data: {data}")
# Evaluate expression against real data
data = {'f0': 2, 'f1': True ,'f2': 's', 'f3': 'foobar'}
_print(wher, data, wher.evaluate(data))
# For different data
data['f3'] = 'bazbar'
_print(wher, data, wher.evaluate(data))
# For different data
data['f0'] = 1
_print(wher, data, wher.evaluate(data))
print(f"Completed. Elapsed: {sw.elapsed(3)}s")
Output of print:
(Ex1) Basic Idea
Query:
. raw: (f0>=2+f1=1+f2='s')|(f3~'foo%')
. compiled: ( ( f0 >= 2 AND f1 = 1 AND f2 = 's' ) OR ( f3 like 'foo%' ) )
Tests:
True w/ data: {'f0': 2, 'f1': True, 'f2': 's', 'f3': 'foobar'}
True w/ data: {'f0': 2, 'f1': True, 'f2': 's', 'f3': 'bazbar'}
False w/ data: {'f0': 1, 'f1': True, 'f2': 's', 'f3': 'bazbar'}
Completed. Elapsed: 0.003s
Query Syntax:
# General:
# Query must begin with '(' and end with ')'
# NOT, IN, BETWEEN must be followed by parenthesis '('
# Boolean Operators:
# AND, OR, NOT
# Equality Operators:
# =, !=, <, <=, >, >=, like
# Special:
# ! --> NOT
# + --> AND
# | --> OR
# <> --> !=
# ~ --> like
Metadata
Release files for whereval 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| whereval-0.1.9.tar.gz | 15.0 kB | Without provenance | Details for whereval-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| whereval-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for whereval-0.1.9-py3-none-any.whl |
Total release size: 29.8 kB
Release files / whereval-0.1.9.tar.gz
| Download URL | whereval-0.1.9.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1997266b5ac6b2ae3133313ae803484e277f6517a54c1080eb74b92b19c3b661
|
|
BLAKE2b-256 checksum How to use checksums |
e3e8802fa2d157878cac833958c88bb27a360771c0c48edcb50cd977741f495f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.11.8 Linux/5.15.0-170-generic
|
Release files / whereval-0.1.9-py3-none-any.whl
| Download URL | whereval-0.1.9-py3-none-any.whl |
|---|---|
| Size | 14.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e152af33311d99da1bbf7e8af4073dc8377c871e6d3eb044f13ac67feec6ff6e
|
|
BLAKE2b-256 checksum How to use checksums |
e1b8ad621bd621ec274bd39568736ab6689f2886b1e21f3210225ab23bc8d510
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.1 CPython/3.11.8 Linux/5.15.0-170-generic
|
Security for whereval 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.