A lightweight, injection-proof query language for multi-dialect SQL generation
Project description
FlyQL
A lightweight, injection-proof query language that parses human-readable filter expressions into a portable AST, transpiles to SQL across ClickHouse, PostgreSQL, and StarRocks, and evaluates in-memory.
Installation
pip install flyql
Requires Python 3.10+.
Quick Start
Parse a query
from flyql import parse
result = parse("status = 200 and active")
print(result.root)
Generate SQL
from flyql import parse
from flyql.generators.clickhouse.generator import to_sql_where
from flyql.generators.clickhouse.column import Column
result = parse("status >= 400 and host like 'prod%'")
columns = {
"status": Column("status", False, "UInt32"),
"host": Column("host", False, "String"),
}
sql = to_sql_where(result.root, columns)
print(sql)
Generators are available for ClickHouse, PostgreSQL, and StarRocks:
from flyql.generators.clickhouse.generator import to_sql_where
from flyql.generators.postgresql.generator import to_sql_where
from flyql.generators.starrocks.generator import to_sql_where
Match in-memory data
from flyql import parse
from flyql.matcher import Evaluator, Record
result = parse("status = 200 and active")
data = {
"status": 200,
"active": True,
"host": "prod-api-01",
}
evaluator = Evaluator()
matches = evaluator.evaluate(result.root, Record(data))
print(f"Matches: {matches}") # True
Transformers
from flyql import parse
from flyql.generators.clickhouse.generator import to_sql_where
from flyql.generators.clickhouse.column import Column
result = parse("message|upper = 'ERROR'")
columns = {"message": Column("message", False, "String")}
sql = to_sql_where(result.root, columns)
print(sql) # equals(upper(message), 'ERROR')
Column parsing
from flyql.columns import parse, parse_to_json
parsed = parse("message, status")
for col in parsed:
print(f"{col.name} (display: {col.display_name!r}, segments: {col.segments})")
# Enable transformers
with_transforms = parse(
"message|chars(25) as msg, status", capabilities={"transformers": True}
)
# Serialize to JSON
json_str = parse_to_json("message, status|upper", capabilities={"transformers": True})
print(json_str)
Query Syntax
Queries consist of conditions connected by boolean operators (and, or, not):
status=200 and active and not archived
service!=api or user="john doe"
message~"error.*" and not debug
(a=1 or b=2) and not (c=3 and d=4)
status in [200, 201] and method not in ['DELETE', 'PUT']
Operators
| Operator | Syntax |
|---|---|
| Equals | = |
| Not equals | != |
| Regex match | ~ |
| Not regex match | !~ |
| Greater than | > |
| Less than | < |
| Greater or equals | >= |
| Less or equals | <= |
| In list | in |
| Not in list | not in |
| Like | like |
| Not like | not like |
| Case-insensitive like | ilike |
| Case-insensitive not like | not ilike |
Documentation
Full documentation: docs.flyql.dev
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flyql-0.0.42.tar.gz.
File metadata
- Download URL: flyql-0.0.42.tar.gz
- Upload date:
- Size: 104.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e01ddd5e59a6cee98fb0fd65158f03bf087f2b4d6f7eb8f35c40d0188269dccd
|
|
| MD5 |
fe8b168ed33bfc8808bf91621cf895eb
|
|
| BLAKE2b-256 |
cb488c7f3ea71fba88cec6d7094fc3c2385a6828760352518293265ece5fb3b0
|
Provenance
The following attestation bundles were made for flyql-0.0.42.tar.gz:
Publisher:
publish.yaml on iamtelescope/flyql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flyql-0.0.42.tar.gz -
Subject digest:
e01ddd5e59a6cee98fb0fd65158f03bf087f2b4d6f7eb8f35c40d0188269dccd - Sigstore transparency entry: 1299200968
- Sigstore integration time:
-
Permalink:
iamtelescope/flyql@b3aac7c96543f12cddd2f44cea132b802dece0b5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/iamtelescope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b3aac7c96543f12cddd2f44cea132b802dece0b5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file flyql-0.0.42-py3-none-any.whl.
File metadata
- Download URL: flyql-0.0.42-py3-none-any.whl
- Upload date:
- Size: 96.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7947e0f590ed99d267ace3e6af4f810d9429ce724d1a4fad1b778d5805f224a
|
|
| MD5 |
a9f353c2550a265e70e24d02ded5b557
|
|
| BLAKE2b-256 |
77aa7856b22fdeadf5a23f0482b602cd29f9122876285452745a1cc221fafa9c
|
Provenance
The following attestation bundles were made for flyql-0.0.42-py3-none-any.whl:
Publisher:
publish.yaml on iamtelescope/flyql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flyql-0.0.42-py3-none-any.whl -
Subject digest:
d7947e0f590ed99d267ace3e6af4f810d9429ce724d1a4fad1b778d5805f224a - Sigstore transparency entry: 1299201088
- Sigstore integration time:
-
Permalink:
iamtelescope/flyql@b3aac7c96543f12cddd2f44cea132b802dece0b5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/iamtelescope
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b3aac7c96543f12cddd2f44cea132b802dece0b5 -
Trigger Event:
workflow_dispatch
-
Statement type: