tellaro-query-language 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,433 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: tellaro-query-language
3
- Version: 0.2.3
4
- Summary: A flexible, human-friendly query language for searching and filtering structured data
5
- Home-page: https://github.com/tellaro/tellaro-query-language
6
- License: MIT
7
- Keywords: query,language,opensearch,elasticsearch,search,filter,tql
8
- Author: Justin Henderson
9
- Author-email: justin@tellaro.io
10
- Requires-Python: >=3.11,<3.14
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3.13
18
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
- Classifier: Topic :: Text Processing :: Linguistic
20
- Provides-Extra: opensearch
21
- Requires-Dist: dnspython (>=2.7.0,<3.0.0)
22
- Requires-Dist: maxminddb (>=2.7.0,<3.0.0)
23
- Requires-Dist: opensearch-dsl (>=2.1.0,<3.0.0) ; extra == "opensearch"
24
- Requires-Dist: opensearch-py (>=2.4.2,<3.0.0) ; extra == "opensearch"
25
- Requires-Dist: pyparsing (>=3.2.1,<4.0.0)
26
- Requires-Dist: setuptools (>=80.0.0,<81.0.0)
27
- Requires-Dist: urllib3 (>=2.5.0,<3.0.0)
28
- Project-URL: Documentation, https://github.com/tellaro/tellaro-query-language/tree/main/docs
29
- Project-URL: Repository, https://github.com/tellaro/tellaro-query-language
30
- Description-Content-Type: text/markdown
31
-
32
- # Tellaro Query Language
33
-
34
- [![PyPI version](https://badge.fury.io/py/tellaro-query-language.svg)](https://badge.fury.io/py/tellaro-query-language)
35
- [![Tests Status](./badges/test-badge.svg?dummy=8484744)](./reports/pytest/junit.xml) [![Coverage Status](./badges/coverage-badge.svg?dummy=8484744)](./reports/coverage/index.html) [![Flake8 Status](./badges/flake8-badge.svg?dummy=8484744)](./reports/flake8/index.html)
36
- [![Python 3.11-3.13](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue)](https://www.python.org/)
37
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
-
39
- ## What is TQL?
40
-
41
- Tellaro Query Language (TQL) is a flexible, human-friendly query language for searching and filtering structured data. TQL is designed to provide a unified, readable syntax for expressing complex queries, supporting both simple and advanced search scenarios. It is especially useful for environments where data may come from different backends (such as OpenSearch or JSON files) and where users want to write queries that are portable and easy to understand.
42
-
43
- TQL supports:
44
- - **Field selection** (including nested fields)
45
- - **Comparison and logical operators**
46
- - **String, number, and list values**
47
- - **Collection operators** (ANY, ALL) for working with list fields
48
- - **Mutators** for post-processing or transforming field values
49
- - **Operator precedence and parenthetical grouping** (AND, OR, NOT, etc.)
50
- - **Field extraction** for analyzing query dependencies
51
- - **Multiple backends** (in-memory evaluation, OpenSearch, file operations)
52
- - **Statistical aggregations** for data analysis
53
-
54
- ---
55
-
56
- ## TQL Syntax Overview
57
-
58
- ### Basic Query Structure
59
-
60
- TQL queries are generally structured as:
61
-
62
- ```
63
- field [| mutator1 | mutator2 ...] operator value
64
- ```
65
-
66
- - **field**: The field to query (e.g., `computer.name`, `os.ver`).
67
- - **mutator**: (Optional) One or more transformations to apply to the field before comparison (e.g., `| lowercase`).
68
- - **operator**: The comparison operator (e.g., `eq`, `contains`, `in`, `>`, `regexp`).
69
- - **value**: The value to compare against (string, number, identifier, or list).
70
-
71
- #### Example
72
-
73
- ```
74
- computer.name | lowercase eq 'ha-jhend'
75
- os.ver > 10
76
- os.dataset in ['windows_server', 'enterprise desktop']
77
- ```
78
-
79
- ### Mutators
80
-
81
- Mutators allow you to transform field values before comparison. For example, `| lowercase` will convert the field value to lowercase before evaluating the condition.
82
-
83
- ```
84
- user.email | lowercase eq 'admin@example.com'
85
- ```
86
-
87
- ### Operators
88
-
89
- TQL supports a variety of comparison operators, including:
90
-
91
- - `eq`, `=`, `ne`, `!=` (equals, not equals)
92
- - `>`, `>=`, `<`, `<=` (greater/less than)
93
- - `contains`, `in`, `regexp`, `startswith`, `endswith`
94
- - `is`, `exists`, `range`, `between`, `cidr`
95
-
96
- ### Values
97
-
98
- Values can be:
99
- - **Strings**: `'value'` or `"value"`
100
- - **Numbers**: `123`, `42`, `1.01`
101
- - **Identifiers**: `computer01`, `admin`
102
- - **Lists**: `["val1", "val2"]`
103
-
104
- ### Logical Expressions
105
-
106
- TQL supports logical operators and grouping:
107
-
108
- ```
109
- field1 eq 'foo' AND (field2 > 10 OR field3 in ['a', 'b'])
110
- NOT field4 contains 'bar'
111
- ```
112
-
113
- Operators supported: `AND`, `OR`, `NOT`, `ANY`, `ALL` (case-insensitive)
114
-
115
- ### Example Query
116
-
117
- ```
118
- computer.name | lowercase eq 'ha-jhend' AND (os.ver > 10 OR os.dataset in ['windows_server', 'enterprise desktop'])
119
- ```
120
-
121
- ---
122
-
123
- ## Why TQL Matters
124
-
125
- TQL provides a consistent, readable way to express queries across different data sources. It abstracts away backend-specific quirks (like OpenSearch's text vs. keyword fields) and lets users focus on what they want to find, not how to write backend-specific queries.
126
-
127
- **Key benefits:**
128
- - **Unified syntax**: Write one query, run it on many backends.
129
- - **Mutators**: Easily transform data inline (e.g., lowercase, trim).
130
- - **Readability**: Queries are easy to read and write, even for complex logic.
131
- - **Extensible**: New operators and mutators can be added as needed.
132
-
133
- ---
134
-
135
- ## Example: TQL in Action
136
-
137
- Suppose you want to find computers named "HA-JHEND" (case-insensitive), running Windows Server or Enterprise Desktop, and with an OS version greater than 10:
138
-
139
- ```
140
- computer.name | lowercase eq 'ha-jhend' AND (os.ver > 10 OR os.dataset in ['windows_server', 'enterprise desktop'])
141
- ```
142
-
143
- This query will:
144
- - Convert `computer.name` to lowercase and compare to `'ha-jhend'`
145
- - Check if `os.ver` is greater than 10
146
- - Check if `os.dataset` is in the provided list
147
-
148
- ---
149
-
150
- ## Implementation Notes
151
-
152
- TQL is implemented using [pyparsing](https://pyparsing-docs.readthedocs.io/en/latest/) to define the grammar and parse queries. The parser supports mutators, operator precedence, and both standard and reversed operator forms (e.g., `'value' in field`).
153
-
154
- See `src/tql/` for the implementation, including the parser grammar and evaluation logic.
155
-
156
- ## Documentation
157
-
158
- For comprehensive documentation, see the [`docs/`](./docs/) folder:
159
-
160
- - **[Getting Started](./docs/getting-started.md)** - Learn TQL basics with development examples
161
- - **[Development Guide](./docs/development-guide.md)** - File operations, testing, and common patterns
162
- - **[OpenSearch Integration](./docs/opensearch-integration.md)** - Convert TQL to OpenSearch DSL and Lucene queries
163
- - **[Syntax Reference](./docs/syntax-reference.md)** - Complete grammar and syntax specification
164
- - **[Operators](./docs/operators.md)** - All comparison and logical operators
165
- - **[Mutators](./docs/mutators.md)** - Field transformation functions (25+ mutators available)
166
- - **[Stats & Aggregations](./docs/stats.md)** - Statistical analysis and data aggregation functions
167
- - **[Examples](./docs/examples.md)** - Real-world query examples for security, DevOps, and business use cases
168
- - **[Best Practices](./docs/best-practices.md)** - Performance optimization and maintainability tips
169
-
170
- ## Quick Start
171
-
172
- ### Installation
173
-
174
- ```bash
175
- # Install from PyPI
176
- pip install tellaro-query-language
177
-
178
- # Or install with OpenSearch support
179
- pip install tellaro-query-language[opensearch]
180
- ```
181
-
182
- ### Basic Usage
183
-
184
- ```python
185
- from tql import TQL
186
-
187
- # Initialize TQL
188
- tql = TQL()
189
-
190
- # Query data
191
- data = [{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]
192
- results = tql.query(data, 'age > 27')
193
- print(f'Found {len(results)} people over 27: {results}')
194
- # Output: Found 1 people over 27: [{'name': 'Alice', 'age': 30}]
195
- ```
196
-
197
- For OpenSearch integration examples and production usage patterns, see the [Package Usage Guide](docs/package-usage-guide.md).
198
-
199
- ### Development Setup
200
-
201
- For contributors and developers who want to work on TQL itself:
202
-
203
- ```bash
204
- # Clone the repository
205
- git clone https://github.com/tellaro/tellaro-query-language.git
206
- cd tellaro-query-language
207
-
208
- # Install with poetry (includes all dev dependencies)
209
- poetry install
210
-
211
- # Load environment variables for integration tests
212
- cp .env.example .env
213
- # Edit .env with your OpenSearch credentials
214
-
215
- # Run tests
216
- poetry run tests
217
- ```
218
-
219
- **Note**: The development setup uses `python-dotenv` to load OpenSearch credentials from `.env` files for integration testing. This is NOT required when using TQL as a package - see the [Package Usage Guide](docs/package-usage-guide.md) for production configuration patterns.
220
-
221
- ### TQL Playground
222
-
223
- The repository includes an interactive web playground for testing TQL queries:
224
-
225
- ```bash
226
- # Navigate to the playground directory
227
- cd playground
228
-
229
- # Start with Docker (recommended)
230
- docker-compose up
231
-
232
- # Or start with OpenSearch included
233
- docker-compose --profile opensearch up
234
- ```
235
-
236
- Access the playground at:
237
- - Frontend: http://localhost:5173
238
- - API: http://localhost:8000
239
- - API Docs: http://localhost:8000/docs
240
-
241
- The playground uses your local TQL source code, so any changes you make are immediately reflected. See [playground/README.md](playground/README.md) for more details.
242
-
243
- ### File Operations
244
-
245
- ```python
246
- from tql import TQL
247
-
248
- # Query JSON files directly
249
- tql = TQL()
250
- results = tql.query("data.json", "user.role eq 'admin' AND status eq 'active'")
251
-
252
- # Query with field mappings for OpenSearch
253
- mappings = {"hostname": "agent.name.keyword"}
254
- tql_mapped = TQL(mappings)
255
- opensearch_dsl = tql_mapped.to_opensearch("hostname eq 'server01'")
256
-
257
- # Extract fields from a complex query
258
- query = "process.name eq 'explorer.exe' AND (user.id eq 'admin' OR user.groups contains 'administrators')"
259
- fields = tql.extract_fields(query)
260
- print(fields) # ['process.name', 'user.groups', 'user.id']
261
- ```
262
-
263
- ### Query Analysis and Health Evaluation
264
-
265
- TQL provides context-aware query analysis to help you understand performance implications before execution:
266
-
267
- ```python
268
- from tql import TQL
269
-
270
- tql = TQL()
271
-
272
- # Analyze for in-memory execution (default)
273
- query = "field | lowercase | trim eq 'test'"
274
- analysis = tql.analyze_query(query) # or explicitly: analyze_query(query, context="in_memory")
275
-
276
- print(f"Health: {analysis['health']['status']}") # 'good' - fast mutators don't impact in-memory
277
- print(f"Score: {analysis['health']['score']}") # 100
278
- print(f"Has mutators: {analysis['stats']['has_mutators']}") # True
279
-
280
- # Analyze the same query for OpenSearch execution
281
- analysis = tql.analyze_query(query, context="opensearch")
282
- print(f"Health: {analysis['health']['status']}") # 'fair' - post-processing required
283
- print(f"Score: {analysis['health']['score']}") # 85
284
-
285
- # Check mutator-specific health
286
- if 'mutator_health' in analysis:
287
- print(f"Mutator health: {analysis['mutator_health']['health_status']}")
288
- for reason in analysis['mutator_health']['health_reasons']:
289
- print(f" - {reason['reason']}")
290
-
291
- # Slow mutators impact both contexts
292
- slow_query = "hostname | nslookup contains 'example.com'"
293
- analysis = tql.analyze_query(slow_query)
294
- print(f"In-memory health: {analysis['health']['status']}") # 'fair' or 'poor' - network I/O
295
-
296
- # Query complexity analysis
297
- complex_query = "(a > 1 OR b < 2) AND (c = 3 OR (d = 4 AND e = 5))"
298
- analysis = tql.analyze_query(complex_query)
299
- print(f"Depth: {analysis['complexity']['depth']}")
300
- print(f"Fields: {analysis['stats']['fields']}")
301
- print(f"Operators: {analysis['stats']['operators']}")
302
- ```
303
-
304
- ### Post-Processing with OpenSearch
305
-
306
- TQL intelligently handles mutators based on field mappings. When OpenSearch can't perform certain operations (like case-insensitive searches on keyword fields), TQL applies post-processing:
307
-
308
- ```python
309
- # Field mappings with only keyword fields
310
- mappings = {"username": {"type": "keyword"}, "department": {"type": "keyword"}}
311
- tql = TQL(mappings)
312
-
313
- # This query requires post-processing since keyword fields can't do case-insensitive contains
314
- query = "username | lowercase contains 'admin' AND department eq 'Engineering'"
315
-
316
- # Analyze the query (analyze_opensearch_query is deprecated, use analyze_query instead)
317
- analysis = tql.analyze_query(query, context="opensearch")
318
- print(f"Health: {analysis['health']['status']}") # 'fair' (post-processing required)
319
-
320
- # Execute with automatic post-processing
321
- result = tql.execute_opensearch(
322
- opensearch_client=client,
323
- index="users",
324
- query=query
325
- )
326
- # OpenSearch returns all Engineering users, TQL filters to only those with 'admin' in username
327
-
328
- # Run the demo to see this in action
329
- # poetry run python post_processing_demo.py
330
- ```
331
-
332
- ### Development Examples
333
-
334
- ```bash
335
- # Run comprehensive demos
336
- poetry run python demo.py # Basic functionality
337
- poetry run python intelligent_mapping_demo.py # Field mapping features
338
- poetry run python test_requested_functionality.py # Core functionality tests
339
- poetry run python field_extraction_demo.py # Field extraction
340
- poetry run python post_processing_demo.py # Post-processing filtering
341
-
342
- # Run tests
343
- poetry run pytest tests/ -v
344
-
345
- # Run integration tests with OpenSearch (requires OpenSearch)
346
- # 1. Copy .env.example to .env and configure connection settings
347
- # 2. Set OPENSEARCH_INTEGRATION_TEST=true in .env
348
- poetry run pytest tests/test_opensearch_integration.py -v
349
- ```
350
-
351
- ## Contributing
352
-
353
- TQL supports 25+ mutators including string manipulation, encoding/decoding, DNS operations, and network analysis. See the [Mutators documentation](./docs/mutators.md) for the complete list.
354
-
355
- To add new mutators or operators, see the implementation in `src/tql/mutators.py` and `src/tql/parser.py`.
356
-
357
- ### Statistical Aggregations
358
-
359
- TQL supports powerful data analysis with stats expressions:
360
-
361
- ```tql
362
- # Simple aggregation
363
- | stats sum(revenue)
364
-
365
- # Grouped analysis
366
- | stats count(requests), average(response_time) by server_name
367
-
368
- # Top N analysis
369
- | stats sum(sales, top 10) by product_category
370
-
371
- # Complex analytics
372
- status eq 'success'
373
- | stats count(requests), sum(bytes), average(response_time), max(cpu_usage) by endpoint
374
- ```
375
-
376
- Stats functions include: `sum`, `min`, `max`, `count`, `unique_count`, `average`, `median`, `percentile_rank`, `zscore`, `std`
377
-
378
- ## Documentation
379
-
380
- Comprehensive documentation is available in the [docs](./docs/) directory:
381
-
382
- - [**Getting Started**](./docs/getting-started.md) - Quick introduction to TQL
383
- - [**Syntax Reference**](./docs/syntax-reference.md) - Complete syntax guide
384
- - [**Operators**](./docs/operators.md) - All comparison and logical operators
385
- - [**Mutators**](./docs/mutators.md) - Field transformation functions
386
- - [**Mutator Caching & Security**](./docs/mutator-caching.md) - Performance optimization and security controls
387
- - [**OpenSearch Integration**](./docs/opensearch-integration.md) - Using TQL with OpenSearch
388
- - [**Examples**](./docs/examples.md) - Real-world query examples
389
- - [**Architecture**](./docs/architecture.md) - Modular architecture and design
390
- - [**Migration Guide**](./docs/migration-guide.md) - Upgrading from older versions
391
-
392
- ## Development
393
-
394
- ### Installation
395
-
396
- ```bash
397
- # Clone the repository
398
- git clone https://github.com/tellaro/tellaro-query-language.git
399
- cd tellaro-query-language
400
-
401
- # Install with poetry
402
- poetry install
403
-
404
- # Or install with pip
405
- pip install -e .
406
- ```
407
-
408
- ### Testing
409
-
410
- This project supports Python 3.11, 3.12, 3.13, and 3.14. We use `nox` for automated testing across all versions.
411
-
412
- ```bash
413
- # Install test dependencies
414
- poetry install --with dev
415
-
416
- # Run tests on all Python versions
417
- poetry run nox -s tests
418
-
419
- # Run tests on a specific version
420
- poetry run nox -s tests-3.12
421
-
422
- # Quick test run (fail fast, no coverage)
423
- poetry run nox -s test_quick
424
-
425
- # Run linting and formatting
426
- poetry run nox -s lint
427
- poetry run nox -s format
428
-
429
- # Run all checks
430
- poetry run nox -s all
431
- ```
432
-
433
- For more detailed testing instructions, see [TESTING.md](TESTING.md).