Py PartiQL Parser
py-partiql-parser is a pure Python tokenizer, parser, and executor for the PartiQL language. PartiQL is an expressive, SQL-compatible query language for relational, semi-structured, and nested data, primarily maintained by Amazon. The library is currently at version 0.6.3 and appears to be actively maintained, with releases indicating ongoing development, though without a fixed cadence.
Warnings
- gotcha The project is described as 'Much beta, such wow' on PyPI. This suggests the library is still under active development and may have evolving APIs or unaddressed edge cases. Users should be mindful of potential changes in future minor versions.
- gotcha The library explicitly notes that AWS's native PartiQL implementation (e.g., in DynamoDB) does not fully follow the PartiQL spec, specifically regarding querying lists of JSON documents (e.g., `SELECT *` vs. `SELECT key` for each document) and lacking `SELECT VALUES`. The parser's behavior might therefore differ from AWS's actual runtime.
- gotcha This library is a *pure Python parser and in-memory executor* of PartiQL. It does *not* directly integrate with `boto3` or AWS services for executing queries against live DynamoDB tables. Users aiming to query live DynamoDB via Python should typically use `boto3`'s `execute_statement` API directly with the PartiQL string. This library is best for parsing, validating, or executing PartiQL against local data structures.
- gotcha A common point of confusion for users of PartiQL with DynamoDB is that DynamoDB's native PartiQL dialect does not support `AS` aliases in `SELECT` clauses, unlike standard SQL. If `py-partiql-parser` supports `AS` in its parsing, the resulting PartiQL string (if re-serialized) or logical intent might not be directly compatible with AWS DynamoDB.
Install
-
pip install py-partiql-parser
Imports
- DynamoDBStatementParser
from py_partiql_parser import DynamoDBStatementParser
Quickstart
from py_partiql_parser import DynamoDBStatementParser
# Instantiate the parser
parser = DynamoDBStatementParser()
# PartiQL statement to parse
statement = "select * from my_table where id = '123'"
# Parse the statement to get the Abstract Syntax Tree (AST)
parsed_ast = parser.parse(statement)
print(f"Parsed AST: {parsed_ast}")
# You can also execute the parsed statement with an in-memory dataset
data = [{"id": "123", "name": "foo"}, {"id": "456", "name": "bar"}]
result = parsed_ast.execute(data)
print(f"Execution result: {result}")