Skip to main content

detection-rules-esql-py

CI Python uv Ruff Version License

Python parser and AST for ES|QL, Elasticsearch’s piped query language.

detection-rules-esql-py parses and checks ES|QL offline — syntax, stack-version feature gates, nested KQL() / EQL(), schema and type checks, and helpers for fields, sources, and rule shape — without sending the query to a cluster.

Elastic Security uses it to validate detection-rules.

Install

pip install detection-rules-esql-py

Quick start

import esql

# Prefer a Python triple-quoted string so ES|QL "..." values need no \" escapes.
tree = esql.parse_query("""
FROM logs-* METADATA _id, _version, _index
| WHERE event.category == "process"
| KEEP @timestamp, host.name, _id, _version, _index
""")
print(esql.get_from_sources(tree))
print(esql.get_unique_fields(tree))

# When the ES|QL string itself contains quotes, use ES|QL's """ delimiter
# (wrap the Python string in '''...''' so the delimiters do not collide):
tree = esql.parse_query('''ROW name = """Indiana "Indy" Jones"""''')

Documentation

Doc Contents
docs/maintaining.md Grammar and definitions sync
docs/detection-rules-integration.md How Elastic Security detection-rules uses the package
CHANGELOG.md Release notes
SUPPORT.md How to get help
CODE_OF_CONDUCT.md Elastic Community Code of Conduct
CONTRIBUTING.md Development setup and PR checklist

Development

git clone git@github.com:elastic/detection-rules-esql-py.git
cd detection-rules-esql-py
uv sync                 # creates .venv + installs package + ruff/pytest
make ci                 # lint + check-generated + test

Grammar maintenance:

make update-window      # sync + generate + check-generated
make ci

Requires uv (brew install uv or see Astral’s install docs).

License

Elastic License 2.0 — see LICENSE.txt.

Release files for detection-rules-esql-py 0.1.0

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

Source distribution (sdist)

Source distribution for detection-rules-esql-py 0.1.0
File Size Uploaded
detection_rules_esql_py-0.1.0.tar.gz 428.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for detection-rules-esql-py 0.1.0
File Interpreter ABI Platform
detection_rules_esql_py-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 861.5 kB

Release files / detection_rules_esql_py-0.1.0.tar.gz

Download URL detection_rules_esql_py-0.1.0.tar.gz
Size 428.7 kB
Tags Source
SHA-256 checksum
How to use checksums
076cb6932d7edc9f06e3bc07728425c00c01ad86c58837bcb415dec8f80adc38
BLAKE2b-256 checksum
How to use checksums
296ef77635ed90533d494cd1ced46ae09db8ce13d8f5f878047419cb8bf8ff92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / detection_rules_esql_py-0.1.0-py3-none-any.whl

Download URL detection_rules_esql_py-0.1.0-py3-none-any.whl
Size 432.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dbc5015be2482dfc62c0b386bb87564c11464c22d52b573b1a44b5f993729fd
BLAKE2b-256 checksum
How to use checksums
3ea2feaa13565c019bcd0f99ce80958740ca97ba4cc47f204dc8b4564e087c23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

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