YAQL - Yet Another Query Language

3.2.0 · active · verified Thu Apr 16

YAQL (Yet Another Query Language) is an embeddable and extensible Python query language designed to perform complex queries against arbitrary objects. It features a comprehensive standard library of querying functions and supports user-defined extensions. The current version is 3.2.0, actively maintained with infrequent releases, and it is distributed via PyPI.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the YAQL engine, load a data source, and execute simple YAQL expressions to filter and select data. The `data` keyword argument is used to pass the input data to the engine.

import yaql
from yaql.factory import YaqlFactory

data_source = {
    'customers': [
        {'name': 'John Doe', 'age': 30, 'city': 'New York', 'orders': [{'id': 1, 'amount': 100}, {'id': 2, 'amount': 250}]},
        {'name': 'Jane Smith', 'age': 24, 'city': 'London', 'orders': [{'id': 3, 'amount': 150}]},
        {'name': 'Peter Jones', 'age': 35, 'city': 'New York', 'orders': []}
    ]
}

# Create a YAQL engine
engine = YaqlFactory().create()

# Evaluate an expression to find customers in New York
expression = '$.customers.where($.city = "New York")'
result = engine(expression)(data=data_source)
print(f"Customers in New York: {list(result)}")

# Evaluate an expression to get names of customers with orders
expression_with_orders = '$.customers.where($.orders.len() >= 1).select($.name)'
result_with_orders = engine(expression_with_orders)(data=data_source)
print(f"Customers with orders: {list(result_with_orders)}")

view raw JSON →