pytrilogy

raw JSON →
0.3.246 verified Fri May 01 auth: no python

A declarative, typed query language that compiles to SQL. Current version 0.3.246. Release cadence is frequent, pre-1.0 breaking changes may occur.

pip install pytrilogy
error ModuleNotFoundError: No module named 'pytrilogy'
cause The library is not installed or the pip package name is misspelled.
fix
Run 'pip install pytrilogy'.
error AttributeError: module 'pytrilogy' has no attribute 'compile'
cause Trying to use pytrilogy.compile after 'import pytrilogy', but compile is not a top-level attribute.
fix
Use 'from pytrilogy import compile' instead.
error TrilogyError: Unrecognized dialect 'mysql'
cause Providing an unsupported dialect string to compile().
fix
Use a supported dialect: 'postgres', 'bigquery', 'sqlite', 'trino', etc. Check the docs for the full list.
error SyntaxError: invalid syntax in Trilogy query at line ...
cause The Trilogy query string contains syntax errors or uses features not yet supported.
fix
Review the Trilogy language documentation and ensure your query is valid. Use a simple query for debugging.
breaking The library is pre-1.0; breaking changes occur frequently. Pin your version or expect sudden API changes.
fix Pin version in requirements, e.g., pytrilogy==0.3.246.
gotcha The 'compile' function must be imported directly from the package. Importing pytrilogy and calling pytrilogy.compile may fail.
fix Use 'from pytrilogy import compile'.
gotcha The library expects a specific dialect string (e.g., 'postgres', 'bigquery', 'sqlite'). Using an unsupported dialect may cause cryptic errors.
fix Check the supported dialects in the documentation. Use a known dialect like 'postgres' or 'bigquery'.
deprecated Older versions used 'from pytrilogy import pytrilogy_compile' or similar; always use the top-level 'compile'.
fix Update to 'from pytrilogy import compile'.

Compile a simple Trilogy query to SQL. The compile function returns an object with .sql and .params attributes.

from pytrilogy import compile

query = '''
import std

# Declare a variable
let x = 5

# Return the variable as a column named "val"
source = from x in std.from_list([x]) select { val: x }
'''

result = compile(query, dialect='postgres')
print(result.sql)