

Trilogy: Composable, reusable analytics — in a SQL-inspired language that’s testable, type-safe, and built for teams. Model once. Run anywhere.
Familiar
Looks like SQL. Feels like code.
Accurate
No gotchas with grouping or joins.
Testable
Type-safe analytics with modular, testable logic.
Efficient
Write less. Stage less. Run what matters.
Extendable
Open source. Rich python API.
Composable
Models as building blocks: share, reuse, and compose with ease.
LLM-Native
Designed to be human-readable and LLM-friendly.
Install
pip install pytrilogy
Trilogy is a data modeling language with first-class support for logic, functions, and reuse. Here's a simple working example:
Hello, World
#-- model logic is written first, like a program
#-- define your model
const greeting <- 'hello';
key object string;
#-- bind it to data
datasource objects (
object:object
)
grain (object)
query '''
select unnest(['world', 'friend', 'visitor']) as object
''';
def initcap(word)-> upper(substring(word, 1, 1)) || substring(word,2, len(word));
#-- and run your SQL
WHERE object like '%world%' or object = 'friend'
SELECT
greeting || ' ' || @initcap(object) || '!' as salutation,
rank salutation by len(salutation) asc as brevity_rank
;