{"id":27318,"library":"pytrilogy","title":"pytrilogy","description":"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.","status":"active","version":"0.3.246","language":"python","source_language":"en","source_url":"https://github.com/trilogy-libraries/pytrilogy","tags":["sql","query-language","compiler","declarative","typed"],"install":[{"cmd":"pip install pytrilogy","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"Direct import of compile function is required.","wrong":"import pytrilogy","symbol":"compile","correct":"from pytrilogy import compile"}],"quickstart":{"code":"from pytrilogy import compile\n\nquery = '''\nimport std\n\n# Declare a variable\nlet x = 5\n\n# Return the variable as a column named \"val\"\nsource = from x in std.from_list([x]) select { val: x }\n'''\n\nresult = compile(query, dialect='postgres')\nprint(result.sql)","lang":"python","description":"Compile a simple Trilogy query to SQL. The compile function returns an object with .sql and .params attributes."},"warnings":[{"fix":"Pin version in requirements, e.g., pytrilogy==0.3.246.","message":"The library is pre-1.0; breaking changes occur frequently. Pin your version or expect sudden API changes.","severity":"breaking","affected_versions":"<1.0"},{"fix":"Use 'from pytrilogy import compile'.","message":"The 'compile' function must be imported directly from the package. Importing pytrilogy and calling pytrilogy.compile may fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Check the supported dialects in the documentation. Use a known dialect like 'postgres' or 'bigquery'.","message":"The library expects a specific dialect string (e.g., 'postgres', 'bigquery', 'sqlite'). Using an unsupported dialect may cause cryptic errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Update to 'from pytrilogy import compile'.","message":"Older versions used 'from pytrilogy import pytrilogy_compile' or similar; always use the top-level 'compile'.","severity":"deprecated","affected_versions":"<0.3.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install pytrilogy'.","cause":"The library is not installed or the pip package name is misspelled.","error":"ModuleNotFoundError: No module named 'pytrilogy'"},{"fix":"Use 'from pytrilogy import compile' instead.","cause":"Trying to use pytrilogy.compile after 'import pytrilogy', but compile is not a top-level attribute.","error":"AttributeError: module 'pytrilogy' has no attribute 'compile'"},{"fix":"Use a supported dialect: 'postgres', 'bigquery', 'sqlite', 'trino', etc. Check the docs for the full list.","cause":"Providing an unsupported dialect string to compile().","error":"TrilogyError: Unrecognized dialect 'mysql'"},{"fix":"Review the Trilogy language documentation and ensure your query is valid. Use a simple query for debugging.","cause":"The Trilogy query string contains syntax errors or uses features not yet supported.","error":"SyntaxError: invalid syntax in Trilogy query at line ..."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}