A package to parse Kusto Query Language (KQL) code
Project description
Kusto Query Language Parser
A parser for parsing KQL queries, including printing parse tree as json and search capabilities. Feel free to request features or make suggestions for improvements
Install
Quick Install
pip install kusto-query-language-parser
Use from Source
Clone repo into your project then run pip install antlr4-python3-runtime==4.8.0
Usage
Check the examples section for example code and an example KQL query for testing
Parse Code
You will need to pip install antlr4-python3-runtime==4.8.0 for creating a file stream or input stream
This will give you an antlr parse tree; the parser also add some further helper functions
from antlr4 import FileStream, InputStream
from kusto__query_language_parser.parser.kql_traverse import KqlTraverse
# parse from file
input_stream = FileStream('input.txt')
# OR parse from text
input_stream = InputStream('_GetWatchlist("Test")')
parser = KqlTraverse()
tree = parser.parse(input_stream)
Get JSON Tree
Traversing an Antlr parse tree can be tedious, the parser provides an alternate visualization of the tree in JSON
# After obtaining the tree above
listener = parser.traverse(tree)
json_tree = parser.get_json_tree(listener)
Searching
You can also search for functions which also returns the arguments along with function name Any expression can also be searched, you can view the JSON tree to see what expressions are available
functions = parser.find_functions(tree)
# e.g. [{'name': '_GetWatchlist', 'arguments': ["'test'"]}]
references = parser.find(tree, "nameReferenceWithDataScope")
# e.g. ['StartTime', 'State']
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 kusto_query_language_parser-0.0.2.tar.gz.
File metadata
- Download URL: kusto_query_language_parser-0.0.2.tar.gz
- Upload date:
- Size: 436.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
803f5519be3d46df341fdc6ddf457dee1ab6cb9d628df9987d06d8d017e3c15a
|
|
| MD5 |
0a48b36fa75ff020b01245a59b14f738
|
|
| BLAKE2b-256 |
1786cbb2183a44de15c7dde4e4012af7548baae12455e6948e30823c5884d976
|
File details
Details for the file kusto_query_language_parser-0.0.2-py3-none-any.whl.
File metadata
- Download URL: kusto_query_language_parser-0.0.2-py3-none-any.whl
- Upload date:
- Size: 449.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06041a340911b001c7508f12b54020306ed2a46333514b168f792f6e23e07e47
|
|
| MD5 |
10cbe3cf7f3e8d3e3fcf17c1ec2bf88e
|
|
| BLAKE2b-256 |
560d063747e8301a21abe227ecba33b5b1a0fb5f6e454e3ffab8ac8cfdd0fdb3
|