semantic-rails 0.1.0__tar.gz

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 (150) hide show
  1. semantic_rails-0.1.0/LICENSE +202 -0
  2. semantic_rails-0.1.0/NOTICE +5 -0
  3. semantic_rails-0.1.0/PKG-INFO +380 -0
  4. semantic_rails-0.1.0/README.md +342 -0
  5. semantic_rails-0.1.0/configs/examples/semantic_rails_capabilities_reference.yml +296 -0
  6. semantic_rails-0.1.0/configs/examples/semantic_rails_package_starter.yml +231 -0
  7. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/caveats.yml +18 -0
  8. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/examples/advanced.yml +530 -0
  9. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/examples/core.yml +52 -0
  10. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/graph.yml +185 -0
  11. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/metrics/core/core_metrics.yml +115 -0
  12. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/metrics/core/time_series_metrics.yml +119 -0
  13. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/metrics/extensions/advanced_metrics.yml +160 -0
  14. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/metrics/extensions/derived_metrics.yml +143 -0
  15. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/metrics/extensions/snapshot_metrics.yml +57 -0
  16. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/calendar.yml +29 -0
  17. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/customers.yml +148 -0
  18. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/daily_metrics.yml +88 -0
  19. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/monthly_metrics.yml +45 -0
  20. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/order_items.yml +80 -0
  21. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/orders.yml +277 -0
  22. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/products.yml +17 -0
  23. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/stores.yml +25 -0
  24. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/core/supplies.yml +38 -0
  25. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/customer_history.yml +28 -0
  26. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/customer_segment_membership.yml +46 -0
  27. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/fiscal_calendar.yml +27 -0
  28. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/order_lifecycle.yml +64 -0
  29. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/store_inventory_snapshots.yml +78 -0
  30. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/models/extensions/storefront_sessions.yml +54 -0
  31. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/package.yml +29 -0
  32. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/policies.yml +41 -0
  33. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/segments/core.yml +23 -0
  34. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/advanced.yml +349 -0
  35. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/api_surface.yml +61 -0
  36. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/authoring.yml +158 -0
  37. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/core.yml +58 -0
  38. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/error_codes.yml +322 -0
  39. semantic_rails-0.1.0/configs/semantic_rails/jaffle_shop/tests/explain.yml +49 -0
  40. semantic_rails-0.1.0/data/jaffle_csv/raw_calendar_fiscal.csv +2315 -0
  41. semantic_rails-0.1.0/data/jaffle_csv/raw_customer_history.csv +8 -0
  42. semantic_rails-0.1.0/data/jaffle_csv/raw_customers.csv +940 -0
  43. semantic_rails-0.1.0/data/jaffle_csv/raw_items.csv +95369 -0
  44. semantic_rails-0.1.0/data/jaffle_csv/raw_order_lifecycle_events.csv +12 -0
  45. semantic_rails-0.1.0/data/jaffle_csv/raw_orders.csv +59653 -0
  46. semantic_rails-0.1.0/data/jaffle_csv/raw_products.csv +11 -0
  47. semantic_rails-0.1.0/data/jaffle_csv/raw_store_inventory_snapshots.csv +16 -0
  48. semantic_rails-0.1.0/data/jaffle_csv/raw_storefront_sessions.csv +11 -0
  49. semantic_rails-0.1.0/data/jaffle_csv/raw_stores.csv +6 -0
  50. semantic_rails-0.1.0/data/jaffle_csv/raw_supplies.csv +66 -0
  51. semantic_rails-0.1.0/data/seed_jaffle.sql +329 -0
  52. semantic_rails-0.1.0/mf2sr/__init__.py +15 -0
  53. semantic_rails-0.1.0/mf2sr/__main__.py +4 -0
  54. semantic_rails-0.1.0/mf2sr/cli.py +105 -0
  55. semantic_rails-0.1.0/mf2sr/filter_parser.py +192 -0
  56. semantic_rails-0.1.0/mf2sr/parsers.py +134 -0
  57. semantic_rails-0.1.0/mf2sr/py.typed +0 -0
  58. semantic_rails-0.1.0/mf2sr/translate.py +1232 -0
  59. semantic_rails-0.1.0/pyproject.toml +179 -0
  60. semantic_rails-0.1.0/semantic_rails/__init__.py +18 -0
  61. semantic_rails-0.1.0/semantic_rails/__main__.py +11 -0
  62. semantic_rails-0.1.0/semantic_rails/api.py +237 -0
  63. semantic_rails-0.1.0/semantic_rails/asgi.py +470 -0
  64. semantic_rails-0.1.0/semantic_rails/ast.py +1094 -0
  65. semantic_rails-0.1.0/semantic_rails/cache.py +149 -0
  66. semantic_rails-0.1.0/semantic_rails/caveats.py +618 -0
  67. semantic_rails-0.1.0/semantic_rails/cli.py +1386 -0
  68. semantic_rails-0.1.0/semantic_rails/compiler.py +3855 -0
  69. semantic_rails-0.1.0/semantic_rails/compiler_parts/__init__.py +1 -0
  70. semantic_rails-0.1.0/semantic_rails/compiler_parts/aliasing.py +158 -0
  71. semantic_rails-0.1.0/semantic_rails/compiler_parts/bind.py +1032 -0
  72. semantic_rails-0.1.0/semantic_rails/compiler_parts/conversion.py +7 -0
  73. semantic_rails-0.1.0/semantic_rails/compiler_parts/grain_recovery.py +326 -0
  74. semantic_rails-0.1.0/semantic_rails/compiler_parts/indexes.py +121 -0
  75. semantic_rails-0.1.0/semantic_rails/compiler_parts/namespacing.py +132 -0
  76. semantic_rails-0.1.0/semantic_rails/compiler_parts/paths.py +428 -0
  77. semantic_rails-0.1.0/semantic_rails/compiler_parts/post_aggregation.py +502 -0
  78. semantic_rails-0.1.0/semantic_rails/compiler_parts/predicate.py +37 -0
  79. semantic_rails-0.1.0/semantic_rails/compiler_parts/sql_lowering.py +3996 -0
  80. semantic_rails-0.1.0/semantic_rails/compiler_parts/temporal.py +911 -0
  81. semantic_rails-0.1.0/semantic_rails/config.py +2654 -0
  82. semantic_rails-0.1.0/semantic_rails/config_parts/__init__.py +1 -0
  83. semantic_rails-0.1.0/semantic_rails/config_parts/package_loader.py +573 -0
  84. semantic_rails-0.1.0/semantic_rails/config_validation.py +2302 -0
  85. semantic_rails-0.1.0/semantic_rails/db.py +270 -0
  86. semantic_rails-0.1.0/semantic_rails/db_parts/__init__.py +0 -0
  87. semantic_rails-0.1.0/semantic_rails/db_parts/base.py +81 -0
  88. semantic_rails-0.1.0/semantic_rails/db_parts/snowflake.py +365 -0
  89. semantic_rails-0.1.0/semantic_rails/diagnostics.py +1352 -0
  90. semantic_rails-0.1.0/semantic_rails/dialects.py +293 -0
  91. semantic_rails-0.1.0/semantic_rails/errors.py +72 -0
  92. semantic_rails-0.1.0/semantic_rails/expressions.py +1771 -0
  93. semantic_rails-0.1.0/semantic_rails/fanout.py +278 -0
  94. semantic_rails-0.1.0/semantic_rails/http_core.py +543 -0
  95. semantic_rails-0.1.0/semantic_rails/http_request.py +197 -0
  96. semantic_rails-0.1.0/semantic_rails/ir.py +167 -0
  97. semantic_rails-0.1.0/semantic_rails/manifest.py +136 -0
  98. semantic_rails-0.1.0/semantic_rails/mcp.py +1922 -0
  99. semantic_rails-0.1.0/semantic_rails/mcp_server.py +502 -0
  100. semantic_rails-0.1.0/semantic_rails/mcp_streamable_http.py +128 -0
  101. semantic_rails-0.1.0/semantic_rails/meta_contract.py +144 -0
  102. semantic_rails-0.1.0/semantic_rails/metadata.py +3651 -0
  103. semantic_rails-0.1.0/semantic_rails/metadata_parts/__init__.py +1 -0
  104. semantic_rails-0.1.0/semantic_rails/metadata_parts/capabilities.py +274 -0
  105. semantic_rails-0.1.0/semantic_rails/metadata_parts/guidance.py +164 -0
  106. semantic_rails-0.1.0/semantic_rails/metadata_parts/object_metadata.py +58 -0
  107. semantic_rails-0.1.0/semantic_rails/metadata_parts/path_coverage.py +165 -0
  108. semantic_rails-0.1.0/semantic_rails/metadata_parts/relevance.py +447 -0
  109. semantic_rails-0.1.0/semantic_rails/metadata_parts/scope_gate.py +26 -0
  110. semantic_rails-0.1.0/semantic_rails/metadata_parts/valid_values.py +235 -0
  111. semantic_rails-0.1.0/semantic_rails/operational.py +201 -0
  112. semantic_rails-0.1.0/semantic_rails/package_tools.py +1435 -0
  113. semantic_rails-0.1.0/semantic_rails/planner/__init__.py +32 -0
  114. semantic_rails-0.1.0/semantic_rails/planner/_base.py +1263 -0
  115. semantic_rails-0.1.0/semantic_rails/planner/generators.py +691 -0
  116. semantic_rails-0.1.0/semantic_rails/planner/intent_ir.py +583 -0
  117. semantic_rails-0.1.0/semantic_rails/planner/orchestrator.py +110 -0
  118. semantic_rails-0.1.0/semantic_rails/planner/patterns/__init__.py +41 -0
  119. semantic_rails-0.1.0/semantic_rails/planner/patterns/_protocol.py +28 -0
  120. semantic_rails-0.1.0/semantic_rails/planner/patterns/distribution_entity_value.py +74 -0
  121. semantic_rails-0.1.0/semantic_rails/planner/patterns/filtered_adoption_funnel.py +118 -0
  122. semantic_rails-0.1.0/semantic_rails/planner/patterns/inline_comparison.py +286 -0
  123. semantic_rails-0.1.0/semantic_rails/planner/patterns/inline_period_shift.py +134 -0
  124. semantic_rails-0.1.0/semantic_rails/planner/patterns/metric_by_dimension_rollup.py +198 -0
  125. semantic_rails-0.1.0/semantic_rails/planner/patterns/qualified_metric_rollup.py +226 -0
  126. semantic_rails-0.1.0/semantic_rails/planner/patterns/runtime_metric_arithmetic.py +66 -0
  127. semantic_rails-0.1.0/semantic_rails/planner/patterns/scoped_predicate_ratio.py +100 -0
  128. semantic_rails-0.1.0/semantic_rails/planner/plan.py +843 -0
  129. semantic_rails-0.1.0/semantic_rails/policies.py +168 -0
  130. semantic_rails-0.1.0/semantic_rails/public_demo.py +104 -0
  131. semantic_rails-0.1.0/semantic_rails/py.typed +0 -0
  132. semantic_rails-0.1.0/semantic_rails/registry.py +224 -0
  133. semantic_rails-0.1.0/semantic_rails/relation_pipelines.py +1162 -0
  134. semantic_rails-0.1.0/semantic_rails/renderer.py +370 -0
  135. semantic_rails-0.1.0/semantic_rails/request_context.py +378 -0
  136. semantic_rails-0.1.0/semantic_rails/runtime.py +2048 -0
  137. semantic_rails-0.1.0/semantic_rails/runtime_parts/__init__.py +1 -0
  138. semantic_rails-0.1.0/semantic_rails/runtime_parts/responses.py +349 -0
  139. semantic_rails-0.1.0/semantic_rails/schema.py +403 -0
  140. semantic_rails-0.1.0/semantic_rails/scope.py +112 -0
  141. semantic_rails-0.1.0/semantic_rails/segments.py +267 -0
  142. semantic_rails-0.1.0/semantic_rails/sql_ast.py +525 -0
  143. semantic_rails-0.1.0/semantic_rails/yaml_loader.py +47 -0
  144. semantic_rails-0.1.0/semantic_rails.egg-info/PKG-INFO +380 -0
  145. semantic_rails-0.1.0/semantic_rails.egg-info/SOURCES.txt +148 -0
  146. semantic_rails-0.1.0/semantic_rails.egg-info/dependency_links.txt +1 -0
  147. semantic_rails-0.1.0/semantic_rails.egg-info/entry_points.txt +2 -0
  148. semantic_rails-0.1.0/semantic_rails.egg-info/requires.txt +12 -0
  149. semantic_rails-0.1.0/semantic_rails.egg-info/top_level.txt +2 -0
  150. semantic_rails-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 WTremml
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ Semantic Rails
2
+ Copyright 2026 WTremml
3
+
4
+ This product is licensed under the Apache License, Version 2.0
5
+ (see the LICENSE file in the root of this repository).
@@ -0,0 +1,380 @@
1
+ Metadata-Version: 2.4
2
+ Name: semantic-rails
3
+ Version: 0.1.0
4
+ Summary: Agent-first semantic layer for governed analytics over DuckDB and Snowflake
5
+ Author: WTremml
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://semantic-rails.com
8
+ Project-URL: Documentation, https://semantic-rails.com/docs/
9
+ Project-URL: Source, https://github.com/semantic-rails/semantic-rails
10
+ Project-URL: Issues, https://github.com/semantic-rails/semantic-rails/issues
11
+ Project-URL: Changelog, https://github.com/semantic-rails/semantic-rails/blob/main/CHANGELOG.md
12
+ Keywords: analytics,duckdb,metrics,semantic-layer,snowflake,sql
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Database
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.11
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ License-File: NOTICE
28
+ Requires-Dist: duckdb>=1.0
29
+ Requires-Dist: PyYAML>=6.0
30
+ Provides-Extra: server
31
+ Requires-Dist: uvicorn>=0.30; extra == "server"
32
+ Provides-Extra: snowflake
33
+ Requires-Dist: snowflake-connector-python>=3.10; extra == "snowflake"
34
+ Provides-Extra: all
35
+ Requires-Dist: uvicorn>=0.30; extra == "all"
36
+ Requires-Dist: snowflake-connector-python>=3.10; extra == "all"
37
+ Dynamic: license-file
38
+
39
+ # Semantic Rails
40
+
41
+ > If your agent can't `discover → inspect → plan/build-options → valid-values → validate → compile → execute` before it queries, you don't have a semantic layer for agents — you have a SQL generator with a metric registry. Semantic Rails is the runtime that makes that loop deterministic.
42
+
43
+ Semantic Rails is an Apache-2.0-licensed, agent-first semantic layer. It ships an MCP server (stdio + HTTP) and an HTTP/JSON API where each of those steps is a separately introspectable tool. Modelling errors — unknown metrics, dimension mismatches, invalid filters, policy violations — are structured envelopes that, where applicable, include `recovery_hints` and `closest_matches`; transport-level errors (invalid JSON, missing auth, unrouted paths) use a leaner envelope with a `code` and `message`. Every off-topic intent is routed through a relevance floor inside `discover` and `plan` before the runtime answers. DuckDB locally, Snowflake through Snow CLI or the native connector.
44
+
45
+ ```bash
46
+ pip install semantic-rails
47
+ semantic-rails packages # lists the bundled jaffle_shop proof package
48
+ semantic-rails query --package jaffle_shop --query-json '{
49
+ "version": 1,
50
+ "select": [{"expression": {"measure": "measure.jaffle.revenue_usd"}, "as": "revenue_usd"}],
51
+ "group_by": ["dimension.jaffle_store_name"],
52
+ "order_by": [{"field": "revenue_usd", "direction": "DESC"}],
53
+ "limit": 5
54
+ }'
55
+ ```
56
+
57
+ The same payload works against `discover`, `validate`, `compile`, and `explain` — each is a
58
+ separate, introspectable step of the same loop. Working from a clone instead (contributors,
59
+ or to use the ready-made payloads under `examples/`):
60
+
61
+ ```bash
62
+ git clone https://github.com/semantic-rails/semantic-rails.git
63
+ cd semantic-rails
64
+ uv sync --group dev
65
+ uv run semantic-rails query --package jaffle_shop --query-json '@examples/jaffle_shop_revenue_by_store.json'
66
+ ```
67
+
68
+ Website: [semantic-rails.com](https://semantic-rails.com) ·
69
+ [Try live](https://semantic-rails.com/try) ·
70
+ [Hosted MCP](https://semantic-rails.com/mcp-docs)
71
+
72
+ License: Apache 2.0; see [LICENSE](LICENSE). Community support, issue reporting, conduct, and security
73
+ reporting are documented in [SUPPORT.md](SUPPORT.md), [CONTRIBUTING.md](CONTRIBUTING.md),
74
+ [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md), and [SECURITY.md](SECURITY.md).
75
+
76
+ ## What Semantic Rails is NOT
77
+
78
+ Three categories readers commonly reach for first. None of them describe this project.
79
+
80
+ - **Not the Open Semantic Interface (OSI).** OSI is a metadata-interchange spec — "the JSON-Schema for semantic layers." Semantic Rails is a runtime: it compiles deterministic SQL, runs an MCP server that exposes `discover → inspect → plan/build-options → valid-values → validate → compile → execute` as separate tools, and ships governed primitives (`metric_predicate`, temporal-validity joins, same-store conversion, contextual entity-graph inheritance) with reviewed guardrails. OSI compatibility would be a metadata adapter we could add later. It would not be the product.
81
+ - **Not another MetricFlow / Cube / Malloy / Snowflake Semantic View.** Those are SQL-generation layers. Semantic Rails is an agent runtime where SQL generation is *one of seven steps an LLM can introspect*. See [comparisons/semantic_layers/](comparisons/semantic_layers/) — on the q01–q07 baseline nearly every layer scores 7 native (Cube takes one workaround, on q05), and the pack shows the cost of the workaround on q08–q16, where Semantic Rails's primitives are first-class.
82
+ - **Not dbt Semantic Layer Cloud.** dbt's Semantic Layer is a hosted product, and its MCP server exposes a handful of semantic-layer tools shaped around list-metrics/get-dimensions/query. Semantic Rails is open-source Apache 2.0, runs locally on DuckDB or Snowflake, and exposes the full loop — discovery, inspection, guided building, validation, compile, and execution — as 13 separately introspectable MCP tools with structured recovery envelopes. The hostable-without-forking work (pluggable audit sinks, env-controlled CORS, per-request limits, in-process reload, public `Runtime.set_compile_cache` seam) makes a future hosted product possible — it is not the OSS product.
83
+
84
+ The shape of the runtime is the differentiator. An MCP server with a relevance floor, structured error envelopes, and seven introspectable steps is not the same primitive as a SQL renderer, even when both can answer "revenue by store last month."
85
+
86
+ ## Runtime Shape
87
+
88
+ - Runtime package: `semantic_rails/`
89
+ - Package configs: `configs/semantic_rails/<package>/`
90
+ - Public website: `website/`
91
+ - Focused tests: `tests/semantic_rails/`
92
+
93
+ ## Documentation
94
+
95
+ Start here depending on what you need:
96
+
97
+ - Project overview and first run: [README.md](README.md)
98
+ - Package authoring: [PACKAGE_AUTHORING.md](docs/PACKAGE_AUTHORING.md)
99
+ - Deployment: [DEPLOYMENT.md](docs/DEPLOYMENT.md)
100
+ - MCP interface: [MCP_INTERFACE.md](docs/MCP_INTERFACE.md)
101
+ - Agent API path: [AGENT_API_PATH.md](docs/AGENT_API_PATH.md)
102
+ - Query AST and API contracts: [QUERY_API.md](docs/QUERY_API.md)
103
+ - Query IR JSON Schema (Draft 2020-12): [QUERY_IR_SCHEMA.md](docs/QUERY_IR_SCHEMA.md) · [schemas/query_ir.v1.json](schemas/query_ir.v1.json)
104
+ - Supported capabilities and current limits: [CAPABILITIES.md](docs/CAPABILITIES.md)
105
+ - Current runtime status: [CURRENT_RUNTIME.md](docs/CURRENT_RUNTIME.md)
106
+ - Architecture spec: [ARCHITECTURE.md](docs/ARCHITECTURE.md)
107
+ - Contributor guide: [CONTRIBUTING.md](CONTRIBUTING.md)
108
+ - Comparative capability evidence vs MetricFlow, Cube, Malloy, and Snowflake Semantic Views: [comparisons/semantic_layers/](comparisons/semantic_layers/)
109
+ - Migrating from MetricFlow: `semantic-rails import --from metricflow` translates a dbt/MetricFlow project into a Semantic Rails package — see [mf2sr/](mf2sr/) for what translates and what is dropped with warnings
110
+ - Annotated reference artifact: [semantic_rails_capabilities_reference.yml](configs/examples/semantic_rails_capabilities_reference.yml)
111
+ - Starter package: [semantic_rails_package_starter.yml](configs/examples/semantic_rails_package_starter.yml)
112
+
113
+ ## Package Naming
114
+
115
+ Semantic Rails is the public product name; the PyPI distribution is `semantic-rails`, the Python import package is `semantic_rails`, and the CLI is `semantic-rails`. The wheel ships the `semantic_rails` package and `mf2sr` (the MetricFlow translator behind `semantic-rails import`). (The project was developed under the `semantic_layer` name, but the unrelated PyPI project `semantic-layer` owns that import namespace, so everything was renamed before first publish — no compatibility shim ships.)
116
+
117
+ ## Quickstart
118
+
119
+ Start from a clean checkout with Python 3.11+ and `uv` installed. If you do not have `uv`, install it from
120
+ [docs.astral.sh/uv](https://docs.astral.sh/uv/) and reopen your shell.
121
+
122
+ ```bash
123
+ git clone https://github.com/semantic-rails/semantic-rails.git
124
+ cd semantic-rails
125
+ ```
126
+
127
+ ```bash
128
+ uv venv
129
+ uv sync --group dev
130
+ ```
131
+
132
+ Build and smoke-test the installable wheel when checking the packaging path:
133
+
134
+ ```bash
135
+ uv build --wheel
136
+ python3 -m venv /tmp/semantic-rails-wheel-smoke
137
+ /tmp/semantic-rails-wheel-smoke/bin/python -m pip install dist/semantic_rails-0.1.0-py3-none-any.whl
138
+ /tmp/semantic-rails-wheel-smoke/bin/semantic-rails packages
139
+ uv run python scripts/verify_package_distribution.py
140
+ ```
141
+
142
+ Without `uv`, install the built wheel into any environment with plain pip:
143
+
144
+ ```bash
145
+ python -m pip install dist/semantic_rails-0.1.0-py3-none-any.whl
146
+ ```
147
+
148
+ The wheel includes the `semantic_rails` runtime, the `semantic-rails` console script, the bundled
149
+ `jaffle_shop` proof package, and its local DuckDB/CSV seed assets. The distribution verifier builds
150
+ a fresh wheel, installs it into an isolated virtual environment, and runs `packages`, `catalog`, and
151
+ `query` from that installed environment.
152
+
153
+ List packages:
154
+
155
+ ```bash
156
+ uv run semantic-rails packages
157
+ ```
158
+
159
+ Expected output includes the bundled proof package:
160
+
161
+ ```text
162
+ jaffle_shop
163
+ ```
164
+
165
+ Inspect catalog and package metadata:
166
+
167
+ ```bash
168
+ uv run semantic-rails catalog --package jaffle_shop
169
+ uv run semantic-rails discover --package jaffle_shop --terms drinks
170
+ uv run semantic-rails inspect --package jaffle_shop --object-id measure.jaffle.order_count
171
+ uv run semantic-rails build-options --package jaffle_shop --query-json '@examples/jaffle_shop_revenue_by_store.json' --step group_by
172
+ uv run semantic-rails plan --package jaffle_shop --intent "new customer orders over time"
173
+ ```
174
+
175
+ Validate, compile, and query:
176
+
177
+ ```bash
178
+ uv run semantic-rails validate --package jaffle_shop --query-json '@examples/jaffle_shop_revenue_by_store.json'
179
+ uv run semantic-rails compile --package jaffle_shop --query-json '@examples/jaffle_shop_revenue_by_store.json'
180
+ uv run semantic-rails query --package jaffle_shop --query-json '@examples/jaffle_shop_revenue_by_store.json'
181
+ ```
182
+
183
+ The `compile` response includes an `explain` payload with the semantic and physical plan, chosen relationship paths, candidate paths, and relationship contracts.
184
+
185
+ A successful query prints a JSON response with `rows`, `row_count`, `output_columns`, and execution metadata. For the
186
+ bundled example, the row data is grouped by store using the local DuckDB fixture at
187
+ `data/jaffle_shop.duckdb`.
188
+
189
+ Parse and validate authored package configs:
190
+
191
+ ```bash
192
+ uv run semantic-rails parse-config --package jaffle_shop
193
+ uv run semantic-rails validate-config --package jaffle_shop
194
+ uv run semantic-rails run-examples --package jaffle_shop
195
+ uv run semantic-rails test-package --package jaffle_shop
196
+ uv run semantic-rails check --package jaffle_shop
197
+ uv run semantic-rails build-package --package jaffle_shop --output dist/jaffle_shop.semantic-rails.tar.gz
198
+ uv run semantic-rails impact-report --package jaffle_shop --base-ref main
199
+ uv run semantic-rails validate-config --path /path/to/package
200
+ ```
201
+
202
+ `check` is the one-command package gate for GitHub-hosted configs. It runs parse, validation probes, package-local examples, package-local tests, and emits a manifest with the package hash. Pass `--artifact path/to/package.tar.gz` to write the deployable config artifact in the same run.
203
+
204
+ Snowflake packages are supported through `package.warehouse: snowflake` plus either
205
+ `package.connection.kind: snowflake_cli` or `snowflake_native`. The sample package is
206
+ [tpch_sf1_showcase](configs/semantic_rails/tpch_sf1_showcase); live validation uses the Snow CLI
207
+ and the configured `semantic_views_trial` connection documented in
208
+ [SNOWFLAKE_SHOWCASE_RUNBOOK.md](docs/SNOWFLAKE_SHOWCASE_RUNBOOK.md). Native Snowflake execution is
209
+ optional and keeps secrets in environment variables or files rather than package YAML.
210
+
211
+ Run the server:
212
+
213
+ ```bash
214
+ uv run semantic-rails serve --package jaffle_shop --port 8081
215
+ ```
216
+
217
+ Run the packaged MCP server:
218
+
219
+ ```bash
220
+ uv run semantic-rails mcp stdio --package jaffle_shop
221
+ uv run semantic-rails mcp http --package jaffle_shop --host 127.0.0.1 --port 8091
222
+ ```
223
+
224
+ The public launch endpoint is stateless MCP Streamable HTTP at
225
+ `https://semantic-rails.com/mcp` using protocol version `2025-11-25`. It is an anonymous,
226
+ scale-to-zero demo fixed to synthetic Jaffle Shop data: no uploads or external credentials,
227
+ 100 executed rows maximum, 25 segment-preview rows maximum, and edge rate/body/deadline limits.
228
+ Use `summary`, `minimal`, or `compact` responses unless a debugging task requires `full`.
229
+
230
+ Run the deployable ASGI service locally:
231
+
232
+ ```bash
233
+ uv run --extra server uvicorn semantic_rails.asgi:app --host 0.0.0.0 --port 8081
234
+ curl -s http://127.0.0.1:8081/api/v1/health
235
+ curl -s http://127.0.0.1:8081/api/v1/ready
236
+ ```
237
+
238
+ Day-1 backend smoke (what a new contributor actually needs):
239
+
240
+ ```bash
241
+ uv run pytest -q tests/semantic_rails -n auto
242
+ uv run semantic-rails check --package jaffle_shop
243
+ ```
244
+
245
+ The full verification matrix — wheel smoke (`scripts/verify_package_distribution.py`),
246
+ release-readiness verifier (`scripts/verify_release_readiness.py`) — is documented in
247
+ [CONTRIBUTING.md § Full Verification Matrix](CONTRIBUTING.md#full-verification-matrix).
248
+
249
+ Snowflake live smoke flow, after configuring the Snow CLI connection:
250
+
251
+ ```bash
252
+ snow connection list
253
+ uv run semantic-rails parse-config --package tpch_sf1_showcase
254
+ uv run semantic-rails validate-config --package tpch_sf1_showcase
255
+ uv run semantic-rails serve --package tpch_sf1_showcase --port 8092
256
+ ```
257
+
258
+ ## Example Query
259
+
260
+ ```json
261
+ {
262
+ "version": 1,
263
+ "select": [
264
+ { "expression": { "measure": "measure.jaffle.revenue_usd" }, "as": "revenue_usd" },
265
+ { "expression": { "metric": "metric.sales.aov_usd" }, "as": "aov_usd" }
266
+ ],
267
+ "group_by": ["dimension.jaffle_store_name"],
268
+ "time": {
269
+ "temporal_role": "temporal_role.jaffle_order_time",
270
+ "grain": "month"
271
+ },
272
+ "policy_context": {
273
+ "environment": "production",
274
+ "audience": "finance"
275
+ },
276
+ "order_by": [{ "field": "revenue_usd", "direction": "DESC" }],
277
+ "limit": 25
278
+ }
279
+ ```
280
+
281
+ For the full request shape and response contracts, use [QUERY_API.md](docs/QUERY_API.md).
282
+
283
+ ## Use from Python
284
+
285
+ Everything the MCP server and CLI expose is available in-process. `Runtime.query` takes the
286
+ same Query IR payload and returns the same envelope, with `rows` as a list of dicts:
287
+
288
+ ```python
289
+ from semantic_rails.runtime import Runtime
290
+
291
+ runtime = Runtime("jaffle_shop")
292
+ result = runtime.query(
293
+ {
294
+ "version": 1,
295
+ "select": [
296
+ {"expression": {"measure": "measure.jaffle.revenue_usd"}, "as": "revenue_usd"}
297
+ ],
298
+ "group_by": ["dimension.jaffle_store_name"],
299
+ "order_by": [{"field": "revenue_usd", "direction": "DESC"}],
300
+ "limit": 5,
301
+ }
302
+ )
303
+ rows = result["rows"] # list[dict] — pd.DataFrame(rows) if you want a frame
304
+ warnings = result["warnings"] # advisory caveats, path warnings, rewrite notes
305
+ runtime.close()
306
+ ```
307
+
308
+ `Runtime("<package-id>")` loads a registered package; `Runtime.from_path("path/to/package")`
309
+ loads a package directory or single-file YAML you are authoring.
310
+
311
+ ## HTTP API
312
+
313
+ Routes are available under stable `/api/v1/*` paths. Discovery, authoring
314
+ assistance, execution, and segments make up the v1 surface of 16 routes —
315
+ the full list with request and response shapes is documented in
316
+ [QUERY_API.md](docs/QUERY_API.md#http-routes). Stability policy: from 0.1.0
317
+ on, `/api/v1` routes are append-only — removing a route or breaking a
318
+ request/response shape requires a new `/api/v2` prefix, even before 1.0.
319
+
320
+ Example:
321
+
322
+ ```bash
323
+ curl -s -X POST http://127.0.0.1:8081/api/v1/query \
324
+ -H 'Content-Type: application/json' \
325
+ -d '{
326
+ "query": {
327
+ "select": [
328
+ { "expression": { "measure": "measure.jaffle.revenue_usd" }, "as": "revenue_usd" }
329
+ ],
330
+ "group_by": ["dimension.jaffle_store_name"],
331
+ "time": { "temporal_role": "temporal_role.jaffle_order_time", "grain": "month" },
332
+ "limit": 5
333
+ }
334
+ }'
335
+ ```
336
+
337
+ ## Active Scope
338
+
339
+ - The only supported runtime is `semantic_rails`.
340
+ - The only supported tests are in `tests/semantic_rails`.
341
+ - The active authored package is [configs/semantic_rails/jaffle_shop](configs/semantic_rails/jaffle_shop), the canonical proof package for release-quality metadata, examples, and package-local primitive tests.
342
+ - See [CONTRIBUTING.md](CONTRIBUTING.md) for the active package, metadata, compiler, and fixture paths.
343
+
344
+ Support tiers, stated plainly: the DuckDB runtime, MCP stdio server, and CLI are the
345
+ supported core — they run in CI on every change. The MetricFlow translator
346
+ ([mf2sr/](mf2sr/), behind `semantic-rails import`) ships in the wheel and its tests run in
347
+ every gate, but its surface is younger than the core's. Snowflake execution (Snow CLI and
348
+ native connector) has dialect-level unit coverage but live execution is exercised manually,
349
+ not in CI. The hosted demo is best-effort. This is currently a single-maintainer project;
350
+ support is best-effort via [SUPPORT.md](SUPPORT.md).
351
+
352
+ ## Current Boundaries
353
+
354
+ - Unsupported mixed-grain paths fail fast with `MIXED_GRAIN_INVALID` or `REWRITE_NOT_SUPPORTED`.
355
+ - Alias resolution returns stable IDs and ambiguity candidates.
356
+ - `build-options` is the primary builder API; `valid-values` searches categorical values for selected dimensions.
357
+ - Supported event-pair conversion metrics execute for the governed event-count model, including same-store variants.
358
+ - The `explain` payload returned by `compile` includes alias resolution, chosen paths, rewrite steps, logical plan, SQL AST, and rendered SQL.
359
+ - Shipped package configs use `expr` AST nodes for measure definitions.
360
+
361
+ ## Relation-Pipeline Claim Boundary
362
+
363
+ Authored `relation:` pipelines are a compile-time primitive — they let authors
364
+ declare `json_explode`, `date_spine`, `anti_join`, and similar steps that lower into reviewed
365
+ SQL CTEs. There is no runtime SQL pipeline endpoint, no arbitrary CTE compiler, and no
366
+ transformation orchestrator. Shipped capabilities are the evidence-backed surface: package
367
+ models with `relation` metadata, graph entities, semantic joins, measures, metrics,
368
+ `metric_predicate`, supported conversion metrics, segments, Query IR, validation, compile,
369
+ explain (which surfaces `chosen_paths`, `candidates`, and `relationship_contract`), and
370
+ execution.
371
+
372
+ Semantic Rails is not a general ELT tool, transformation orchestrator, arbitrary CTE
373
+ pipeline compiler, managed materialization service, or unrestricted nested-predicate planner —
374
+ if you need those, pair it with the tools that do them well.
375
+
376
+ ## License
377
+
378
+ This repository is open source under the Apache License 2.0. See [LICENSE](LICENSE) for the canonical
379
+ terms, [SUPPORT.md](SUPPORT.md) for community support channels, and
380
+ [SECURITY.md](SECURITY.md) for vulnerability reporting.