pytrilogy 0.3.149__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. LICENSE.md +19 -0
  2. _preql_import_resolver/__init__.py +5 -0
  3. _preql_import_resolver/_preql_import_resolver.cp313-win_amd64.pyd +0 -0
  4. pytrilogy-0.3.149.dist-info/METADATA +555 -0
  5. pytrilogy-0.3.149.dist-info/RECORD +207 -0
  6. pytrilogy-0.3.149.dist-info/WHEEL +4 -0
  7. pytrilogy-0.3.149.dist-info/entry_points.txt +2 -0
  8. pytrilogy-0.3.149.dist-info/licenses/LICENSE.md +19 -0
  9. trilogy/__init__.py +27 -0
  10. trilogy/ai/README.md +10 -0
  11. trilogy/ai/__init__.py +19 -0
  12. trilogy/ai/constants.py +92 -0
  13. trilogy/ai/conversation.py +107 -0
  14. trilogy/ai/enums.py +7 -0
  15. trilogy/ai/execute.py +50 -0
  16. trilogy/ai/models.py +34 -0
  17. trilogy/ai/prompts.py +100 -0
  18. trilogy/ai/providers/__init__.py +0 -0
  19. trilogy/ai/providers/anthropic.py +106 -0
  20. trilogy/ai/providers/base.py +24 -0
  21. trilogy/ai/providers/google.py +146 -0
  22. trilogy/ai/providers/openai.py +89 -0
  23. trilogy/ai/providers/utils.py +68 -0
  24. trilogy/authoring/README.md +3 -0
  25. trilogy/authoring/__init__.py +148 -0
  26. trilogy/constants.py +119 -0
  27. trilogy/core/README.md +52 -0
  28. trilogy/core/__init__.py +0 -0
  29. trilogy/core/constants.py +6 -0
  30. trilogy/core/enums.py +454 -0
  31. trilogy/core/env_processor.py +239 -0
  32. trilogy/core/environment_helpers.py +320 -0
  33. trilogy/core/ergonomics.py +193 -0
  34. trilogy/core/exceptions.py +123 -0
  35. trilogy/core/functions.py +1240 -0
  36. trilogy/core/graph_models.py +142 -0
  37. trilogy/core/internal.py +85 -0
  38. trilogy/core/models/__init__.py +0 -0
  39. trilogy/core/models/author.py +2670 -0
  40. trilogy/core/models/build.py +2603 -0
  41. trilogy/core/models/build_environment.py +165 -0
  42. trilogy/core/models/core.py +506 -0
  43. trilogy/core/models/datasource.py +436 -0
  44. trilogy/core/models/environment.py +756 -0
  45. trilogy/core/models/execute.py +1213 -0
  46. trilogy/core/optimization.py +251 -0
  47. trilogy/core/optimizations/__init__.py +12 -0
  48. trilogy/core/optimizations/base_optimization.py +17 -0
  49. trilogy/core/optimizations/hide_unused_concept.py +47 -0
  50. trilogy/core/optimizations/inline_datasource.py +102 -0
  51. trilogy/core/optimizations/predicate_pushdown.py +245 -0
  52. trilogy/core/processing/README.md +94 -0
  53. trilogy/core/processing/READMEv2.md +121 -0
  54. trilogy/core/processing/VIRTUAL_UNNEST.md +30 -0
  55. trilogy/core/processing/__init__.py +0 -0
  56. trilogy/core/processing/concept_strategies_v3.py +508 -0
  57. trilogy/core/processing/constants.py +15 -0
  58. trilogy/core/processing/discovery_node_factory.py +451 -0
  59. trilogy/core/processing/discovery_utility.py +548 -0
  60. trilogy/core/processing/discovery_validation.py +167 -0
  61. trilogy/core/processing/graph_utils.py +43 -0
  62. trilogy/core/processing/node_generators/README.md +9 -0
  63. trilogy/core/processing/node_generators/__init__.py +31 -0
  64. trilogy/core/processing/node_generators/basic_node.py +160 -0
  65. trilogy/core/processing/node_generators/common.py +270 -0
  66. trilogy/core/processing/node_generators/constant_node.py +38 -0
  67. trilogy/core/processing/node_generators/filter_node.py +315 -0
  68. trilogy/core/processing/node_generators/group_node.py +213 -0
  69. trilogy/core/processing/node_generators/group_to_node.py +117 -0
  70. trilogy/core/processing/node_generators/multiselect_node.py +207 -0
  71. trilogy/core/processing/node_generators/node_merge_node.py +695 -0
  72. trilogy/core/processing/node_generators/recursive_node.py +88 -0
  73. trilogy/core/processing/node_generators/rowset_node.py +165 -0
  74. trilogy/core/processing/node_generators/select_helpers/__init__.py +0 -0
  75. trilogy/core/processing/node_generators/select_helpers/datasource_injection.py +261 -0
  76. trilogy/core/processing/node_generators/select_merge_node.py +846 -0
  77. trilogy/core/processing/node_generators/select_node.py +95 -0
  78. trilogy/core/processing/node_generators/synonym_node.py +98 -0
  79. trilogy/core/processing/node_generators/union_node.py +91 -0
  80. trilogy/core/processing/node_generators/unnest_node.py +182 -0
  81. trilogy/core/processing/node_generators/window_node.py +201 -0
  82. trilogy/core/processing/nodes/README.md +28 -0
  83. trilogy/core/processing/nodes/__init__.py +179 -0
  84. trilogy/core/processing/nodes/base_node.py +522 -0
  85. trilogy/core/processing/nodes/filter_node.py +75 -0
  86. trilogy/core/processing/nodes/group_node.py +194 -0
  87. trilogy/core/processing/nodes/merge_node.py +420 -0
  88. trilogy/core/processing/nodes/recursive_node.py +46 -0
  89. trilogy/core/processing/nodes/select_node_v2.py +242 -0
  90. trilogy/core/processing/nodes/union_node.py +53 -0
  91. trilogy/core/processing/nodes/unnest_node.py +62 -0
  92. trilogy/core/processing/nodes/window_node.py +56 -0
  93. trilogy/core/processing/utility.py +823 -0
  94. trilogy/core/query_processor.py +604 -0
  95. trilogy/core/statements/README.md +35 -0
  96. trilogy/core/statements/__init__.py +0 -0
  97. trilogy/core/statements/author.py +536 -0
  98. trilogy/core/statements/build.py +0 -0
  99. trilogy/core/statements/common.py +20 -0
  100. trilogy/core/statements/execute.py +155 -0
  101. trilogy/core/table_processor.py +66 -0
  102. trilogy/core/utility.py +8 -0
  103. trilogy/core/validation/README.md +46 -0
  104. trilogy/core/validation/__init__.py +0 -0
  105. trilogy/core/validation/common.py +161 -0
  106. trilogy/core/validation/concept.py +146 -0
  107. trilogy/core/validation/datasource.py +227 -0
  108. trilogy/core/validation/environment.py +73 -0
  109. trilogy/core/validation/fix.py +256 -0
  110. trilogy/dialect/__init__.py +32 -0
  111. trilogy/dialect/base.py +1432 -0
  112. trilogy/dialect/bigquery.py +314 -0
  113. trilogy/dialect/common.py +147 -0
  114. trilogy/dialect/config.py +159 -0
  115. trilogy/dialect/dataframe.py +50 -0
  116. trilogy/dialect/duckdb.py +397 -0
  117. trilogy/dialect/enums.py +151 -0
  118. trilogy/dialect/metadata.py +173 -0
  119. trilogy/dialect/mock.py +190 -0
  120. trilogy/dialect/postgres.py +117 -0
  121. trilogy/dialect/presto.py +110 -0
  122. trilogy/dialect/results.py +89 -0
  123. trilogy/dialect/snowflake.py +129 -0
  124. trilogy/dialect/sql_server.py +137 -0
  125. trilogy/engine.py +48 -0
  126. trilogy/execution/__init__.py +17 -0
  127. trilogy/execution/config.py +119 -0
  128. trilogy/execution/state/__init__.py +0 -0
  129. trilogy/execution/state/exceptions.py +26 -0
  130. trilogy/execution/state/file_state_store.py +0 -0
  131. trilogy/execution/state/sqllite_state_store.py +0 -0
  132. trilogy/execution/state/state_store.py +406 -0
  133. trilogy/executor.py +692 -0
  134. trilogy/hooks/__init__.py +4 -0
  135. trilogy/hooks/base_hook.py +40 -0
  136. trilogy/hooks/graph_hook.py +135 -0
  137. trilogy/hooks/query_debugger.py +166 -0
  138. trilogy/metadata/__init__.py +0 -0
  139. trilogy/parser.py +10 -0
  140. trilogy/parsing/README.md +21 -0
  141. trilogy/parsing/__init__.py +0 -0
  142. trilogy/parsing/common.py +1069 -0
  143. trilogy/parsing/config.py +5 -0
  144. trilogy/parsing/exceptions.py +8 -0
  145. trilogy/parsing/helpers.py +1 -0
  146. trilogy/parsing/parse_engine.py +2876 -0
  147. trilogy/parsing/render.py +775 -0
  148. trilogy/parsing/trilogy.lark +546 -0
  149. trilogy/py.typed +0 -0
  150. trilogy/render.py +45 -0
  151. trilogy/scripts/README.md +9 -0
  152. trilogy/scripts/__init__.py +0 -0
  153. trilogy/scripts/agent.py +41 -0
  154. trilogy/scripts/agent_info.py +306 -0
  155. trilogy/scripts/common.py +432 -0
  156. trilogy/scripts/dependency/Cargo.lock +617 -0
  157. trilogy/scripts/dependency/Cargo.toml +39 -0
  158. trilogy/scripts/dependency/README.md +131 -0
  159. trilogy/scripts/dependency/build.sh +25 -0
  160. trilogy/scripts/dependency/src/directory_resolver.rs +387 -0
  161. trilogy/scripts/dependency/src/lib.rs +16 -0
  162. trilogy/scripts/dependency/src/main.rs +770 -0
  163. trilogy/scripts/dependency/src/parser.rs +435 -0
  164. trilogy/scripts/dependency/src/preql.pest +208 -0
  165. trilogy/scripts/dependency/src/python_bindings.rs +311 -0
  166. trilogy/scripts/dependency/src/resolver.rs +716 -0
  167. trilogy/scripts/dependency/tests/base.preql +3 -0
  168. trilogy/scripts/dependency/tests/cli_integration.rs +377 -0
  169. trilogy/scripts/dependency/tests/customer.preql +6 -0
  170. trilogy/scripts/dependency/tests/main.preql +9 -0
  171. trilogy/scripts/dependency/tests/orders.preql +7 -0
  172. trilogy/scripts/dependency/tests/test_data/base.preql +9 -0
  173. trilogy/scripts/dependency/tests/test_data/consumer.preql +1 -0
  174. trilogy/scripts/dependency.py +323 -0
  175. trilogy/scripts/display.py +555 -0
  176. trilogy/scripts/environment.py +59 -0
  177. trilogy/scripts/fmt.py +32 -0
  178. trilogy/scripts/ingest.py +487 -0
  179. trilogy/scripts/ingest_helpers/__init__.py +1 -0
  180. trilogy/scripts/ingest_helpers/foreign_keys.py +123 -0
  181. trilogy/scripts/ingest_helpers/formatting.py +93 -0
  182. trilogy/scripts/ingest_helpers/typing.py +161 -0
  183. trilogy/scripts/init.py +105 -0
  184. trilogy/scripts/parallel_execution.py +762 -0
  185. trilogy/scripts/plan.py +189 -0
  186. trilogy/scripts/refresh.py +161 -0
  187. trilogy/scripts/run.py +79 -0
  188. trilogy/scripts/serve.py +202 -0
  189. trilogy/scripts/serve_helpers/__init__.py +41 -0
  190. trilogy/scripts/serve_helpers/file_discovery.py +142 -0
  191. trilogy/scripts/serve_helpers/index_generation.py +206 -0
  192. trilogy/scripts/serve_helpers/models.py +38 -0
  193. trilogy/scripts/single_execution.py +131 -0
  194. trilogy/scripts/testing.py +143 -0
  195. trilogy/scripts/trilogy.py +75 -0
  196. trilogy/std/__init__.py +0 -0
  197. trilogy/std/color.preql +3 -0
  198. trilogy/std/date.preql +13 -0
  199. trilogy/std/display.preql +18 -0
  200. trilogy/std/geography.preql +22 -0
  201. trilogy/std/metric.preql +15 -0
  202. trilogy/std/money.preql +67 -0
  203. trilogy/std/net.preql +14 -0
  204. trilogy/std/ranking.preql +7 -0
  205. trilogy/std/report.preql +5 -0
  206. trilogy/std/semantic.preql +6 -0
  207. trilogy/utility.py +34 -0
@@ -0,0 +1,306 @@
1
+ """Agent info command - outputs AGENTS.md-style usage guide for AI agents."""
2
+
3
+ from click import pass_context
4
+
5
+ from trilogy.ai.prompts import get_trilogy_prompt
6
+
7
+ AGENT_INFO_OUTPUT = """# Trilogy CLI - AI Agent Usage Guide
8
+
9
+ ## Overview
10
+
11
+ Trilogy is a semantic ETL and reporting tool providing a SQL-like language with
12
+ optimizations. This CLI enables workspace management, script execution, testing,
13
+ and data ingestion.
14
+
15
+ ## Quick Start
16
+
17
+ ```bash
18
+ # Initialize a new workspace
19
+ trilogy init [path]
20
+
21
+ # Run a script
22
+ trilogy run script.preql dialect [connection_args...]
23
+
24
+ # Run unit tests (mocked datasources)
25
+ trilogy unit script.preql
26
+
27
+ # Run integration tests (real connections)
28
+ trilogy integration script.preql dialect [connection_args...]
29
+ ```
30
+
31
+ ## Commands Reference
32
+
33
+ ### trilogy init [path]
34
+
35
+ Create a new Trilogy workspace with default configuration and structure.
36
+
37
+ **Arguments:**
38
+ - `path` (optional): Directory to initialize (default: current directory)
39
+
40
+ **Creates:**
41
+ - `trilogy.toml` - Configuration file
42
+ - `raw/` - Directory for raw data models
43
+ - `derived/` - Directory for derived data models
44
+ - `jobs/` - Directory for job scripts
45
+ - `hello_world.preql` - Example script
46
+
47
+ **Example:**
48
+ ```bash
49
+ trilogy init my_project
50
+ cd my_project
51
+ trilogy unit hello_world.preql
52
+ ```
53
+
54
+ ---
55
+
56
+ ### trilogy run <input> [dialect] [options] [conn_args...]
57
+
58
+ Execute a Trilogy script or all scripts in a directory.
59
+
60
+ **Arguments:**
61
+ - `input` (required): Path to .preql file or directory
62
+ - `dialect` (optional): Database dialect (duckdb, postgres, snowflake, bigquery, etc.)
63
+ - `conn_args` (optional): Connection arguments passed to the database driver
64
+
65
+ **Options:**
66
+ - `--param KEY=VALUE`: Environment parameters (can be repeated)
67
+ - `--parallelism N`, `-p N`: Max parallel workers for directory execution
68
+ - `--config PATH`: Path to trilogy.toml configuration file
69
+
70
+ **Examples:**
71
+ ```bash
72
+ # Run single script with DuckDB
73
+ trilogy run query.preql duckdb
74
+
75
+ # Run with connection string
76
+ trilogy run etl.preql postgres "postgresql://user:pass@host/db"
77
+
78
+ # Run directory with parallelism
79
+ trilogy run jobs/ duckdb -p 4
80
+
81
+ # Run with parameters
82
+ trilogy run report.preql duckdb --param date=2024-01-01 --param region=US
83
+ ```
84
+
85
+ ---
86
+
87
+ ### trilogy unit <input> [options]
88
+
89
+ Run unit tests on Trilogy scripts with mocked datasources. Always uses DuckDB.
90
+
91
+ **Arguments:**
92
+ - `input` (required): Path to .preql file or directory
93
+
94
+ **Options:**
95
+ - `--param KEY=VALUE`: Environment parameters
96
+ - `--parallelism N`, `-p N`: Max parallel workers
97
+ - `--config PATH`: Path to trilogy.toml
98
+
99
+ **Examples:**
100
+ ```bash
101
+ # Test single file
102
+ trilogy unit test_query.preql
103
+
104
+ # Test entire directory
105
+ trilogy unit tests/ -p 4
106
+ ```
107
+
108
+ ---
109
+
110
+ ### trilogy integration <input> [dialect] [options] [conn_args...]
111
+
112
+ Run integration tests on Trilogy scripts with real database connections. Integration tests
113
+ run validation that all datasources are configured properly. They do not execute code.
114
+
115
+ To set up new tables, run first then do integration.
116
+
117
+ **Arguments:**
118
+ - `input` (required): Path to .preql file or directory
119
+ - `dialect` (optional): Database dialect
120
+ - `conn_args` (optional): Connection arguments
121
+
122
+ **Options:**
123
+ - `--param KEY=VALUE`: Environment parameters
124
+ - `--parallelism N`, `-p N`: Max parallel workers
125
+ - `--config PATH`: Path to trilogy.toml
126
+
127
+ **Examples:**
128
+ ```bash
129
+ # Integration test against Postgres
130
+ trilogy integration tests/ postgres "postgresql://localhost/testdb"
131
+ ```
132
+
133
+ ---
134
+
135
+ ### trilogy fmt <input>
136
+
137
+ Format a Trilogy script file.
138
+
139
+ **Arguments:**
140
+ - `input` (required): Path to .preql file to format
141
+
142
+ **Example:**
143
+ ```bash
144
+ trilogy fmt messy_script.preql
145
+ ```
146
+
147
+ ---
148
+
149
+ ### trilogy ingest <tables> [dialect] [options] [conn_args...]
150
+
151
+ Bootstrap datasources from existing warehouse tables. Connects to a database,
152
+ introspects table schemas, and generates Trilogy datasource definitions.
153
+
154
+ **Arguments:**
155
+ - `tables` (required): Comma-separated list of table names
156
+ - `dialect` (optional): Database dialect
157
+ - `conn_args` (optional): Connection arguments
158
+
159
+ **Options:**
160
+ - `--output PATH`, `-o PATH`: Output directory for generated files
161
+ - `--schema NAME`, `-s NAME`: Schema/database to ingest from
162
+ - `--config PATH`: Path to trilogy.toml
163
+ - `--fks SPEC`: Foreign key relationships (format: table.col:ref_table.col)
164
+
165
+ **Examples:**
166
+ ```bash
167
+ # Ingest tables from DuckDB
168
+ trilogy ingest "users,orders,products" duckdb "path/to/db.duckdb"
169
+
170
+ # Ingest with schema and output directory
171
+ trilogy ingest "customers" postgres -s public -o raw/ "postgresql://localhost/db"
172
+
173
+ # Ingest with foreign key relationships
174
+ trilogy ingest "orders,customers" duckdb --fks "orders.customer_id:customers.id"
175
+ ```
176
+
177
+ ---
178
+
179
+ ### trilogy serve <directory> [engine] [options]
180
+
181
+ Start a FastAPI server to expose Trilogy models from a directory.
182
+ Requires `pytrilogy[serve]` extras.
183
+
184
+ **Arguments:**
185
+ - `directory` (required): Directory containing model files
186
+ - `engine` (optional): Engine type (default: generic)
187
+
188
+ **Options:**
189
+ - `--port N`, `-p N`: Port number (default: 8100)
190
+ - `--host HOST`, `-h HOST`: Host to bind (default: 0.0.0.0)
191
+ - `--timeout N`, `-t N`: Shutdown after N seconds
192
+
193
+ **Endpoints exposed:**
194
+ - `/` - Server info
195
+ - `/index.json` - List of available models
196
+ - `/models/<name>.json` - Specific model details
197
+ - `/files/<name>` - Raw .preql/.sql file content
198
+
199
+ **Example:**
200
+ ```bash
201
+ trilogy serve ./models/ duckdb --port 8080
202
+ ```
203
+
204
+ ---
205
+
206
+ ### trilogy agent <command> [options]
207
+
208
+ Pass off a multi-step orchestration task to an AI agent. (Not yet implemented)
209
+
210
+ **Arguments:**
211
+ - `command` (required): Natural language command
212
+
213
+ **Options:**
214
+ - `--context PATH`, `-c PATH`: Additional context files
215
+ - `--model NAME`, `-m NAME`: AI model to use
216
+ - `--interactive`, `-i`: Interactive mode with feedback
217
+
218
+ ---
219
+
220
+ ## Configuration File (trilogy.toml)
221
+
222
+ ```toml
223
+ [engine]
224
+ # Default dialect for execution
225
+ dialect = "duckdb"
226
+
227
+ # Max parallelism for multi-script execution
228
+ parallelism = 3
229
+
230
+ [setup]
231
+ # Startup scripts to run before execution
232
+ trilogy = ["setup.preql"]
233
+ sql = ["init.sql"]
234
+ ```
235
+
236
+ ## Supported Dialects
237
+
238
+ - `duckdb` / `duck_db` - DuckDB (default for unit tests)
239
+ - `postgres` / `postgresql` - PostgreSQL
240
+ - `bigquery` - Google BigQuery
241
+ - `snowflake` - Snowflake
242
+ - `redshift` - Amazon Redshift
243
+ - `trino` - Trino/Presto
244
+ - `sql_server` - Microsoft SQL Server
245
+
246
+ ## File Types
247
+
248
+ - `.preql` - Trilogy script files (main language)
249
+ - `.sql` - Raw SQL files (for setup scripts)
250
+ - `trilogy.toml` - Configuration file
251
+
252
+ ## Common Workflows
253
+
254
+ ### 1. Setting up a new project
255
+ ```bash
256
+ trilogy init my_analytics
257
+ cd my_analytics
258
+ # Configure trilogy.toml with your dialect and connection
259
+ trilogy unit hello_world.preql
260
+ ```
261
+
262
+ ### 2. Ingesting existing tables
263
+ ```bash
264
+ trilogy ingest "fact_sales,dim_customers,dim_products" postgres \\
265
+ -s analytics -o raw/ "postgresql://localhost/warehouse"
266
+ ```
267
+
268
+ ### 3. Running ETL jobs
269
+ ```bash
270
+ trilogy run jobs/ postgres -p 4 "postgresql://localhost/warehouse"
271
+ ```
272
+
273
+ ### 4. Testing before deployment
274
+ ```bash
275
+ # Unit tests (fast, no connection needed)
276
+ trilogy unit .
277
+
278
+ # Integration tests (real connection)
279
+ trilogy integration . postgres "postgresql://localhost/testdb"
280
+ ```
281
+
282
+ ## Debug Mode
283
+
284
+ Add `--debug` flag to any command for verbose output:
285
+ ```bash
286
+ trilogy --debug run query.preql duckdb
287
+ ```
288
+ """
289
+
290
+
291
+ def get_agent_info_output() -> str:
292
+ """Build the complete agent info output with CLI docs and syntax reference."""
293
+ syntax_section = get_trilogy_prompt(
294
+ intro="## Trilogy Language Syntax\n\nTrilogy is a SQL-inspired language with a built-in semantic layer. Use the following syntax reference when writing .preql files.",
295
+ )
296
+ return AGENT_INFO_OUTPUT + "\n" + syntax_section
297
+
298
+
299
+ @pass_context
300
+ def agent_info(ctx):
301
+ """Output comprehensive CLI documentation for AI agents.
302
+
303
+ Prints an AGENTS.md-style guide with all commands, options,
304
+ and usage examples optimized for AI agent consumption.
305
+ """
306
+ print(get_agent_info_output())