Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flyql-0.0.40.tar.gz (100.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flyql-0.0.40-py3-none-any.whl (93.0 kB view details)

Uploaded Python 3

File details

Details for the file flyql-0.0.40.tar.gz.

File metadata

  • Download URL: flyql-0.0.40.tar.gz
  • Upload date:
  • Size: 100.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flyql-0.0.40.tar.gz
Algorithm Hash digest
SHA256 9f0ead4a49b3e1220fc38d5db99e4c09dc53e136bb6a4d00056aa6ef817b9872
MD5 4a7cac8f99e22d8a159b52da918e6679
BLAKE2b-256 4e758fd6302d5a6b015c02ae5a3d90848951994fbfb1e53fa218f8aa1f0be6df

See more details on using hashes here.

Provenance

The following attestation bundles were made for flyql-0.0.40.tar.gz:

Publisher: publish.yaml on iamtelescope/flyql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flyql-0.0.40-py3-none-any.whl.

File metadata

  • Download URL: flyql-0.0.40-py3-none-any.whl
  • Upload date:
  • Size: 93.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flyql-0.0.40-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3b17345d3785a3b8b62c5d39813bf1a90094ea9fbb14d9fe8f3250066f3340
MD5 e113a185a36cf241ecba9b42ecbfb949
BLAKE2b-256 01098273b371613b3c0fe6fb583c898db293b4c5ef5e30842e15a374e3e855d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for flyql-0.0.40-py3-none-any.whl:

Publisher: publish.yaml on iamtelescope/flyql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page