AxiomQuery 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.
@@ -0,0 +1,64 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ release-build:
20
+ runs-on: ubuntu-latest
21
+
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+
25
+ - uses: actions/setup-python@v5
26
+ with:
27
+ python-version: "3.x"
28
+
29
+ - name: Build release distributions
30
+ run: |
31
+ python -m pip install build hatchling
32
+ python -m build
33
+
34
+ - name: Upload distributions
35
+ uses: actions/upload-artifact@v4
36
+ with:
37
+ name: release-dists
38
+ path: dist/
39
+
40
+ pypi-publish:
41
+ runs-on: ubuntu-latest
42
+ needs:
43
+ - release-build
44
+ permissions:
45
+ # IMPORTANT: this permission is mandatory for trusted publishing
46
+ id-token: write
47
+
48
+ # Dedicated environments with protections for publishing are strongly recommended.
49
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
50
+ environment:
51
+ name: pypi
52
+ url: https://pypi.org/p/AxiomQuery
53
+
54
+ steps:
55
+ - name: Retrieve release distributions
56
+ uses: actions/download-artifact@v4
57
+ with:
58
+ name: release-dists
59
+ path: dist/
60
+
61
+ - name: Publish release distributions to PyPI
62
+ uses: pypa/gh-action-pypi-publish@release/v1
63
+ with:
64
+ packages-dir: dist/
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to `AxiomQuery` are documented here.
4
+
5
+ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ---
9
+
10
+ ## [0.1.0] — 2026-03-29
11
+
12
+ Initial release.
13
+
14
+ ### Added
15
+
16
+ - `QueryEngine` — specification-based query facade for any SQLAlchemy 2.0 ORM model
17
+ - `list()` / `alist()` — filtered record retrieval with `limit`, `offset`, `order_by`
18
+ - `read_group()` / `aread_group()` — grouped aggregation (GROUP BY + HAVING) with `__domain` drill-down per group
19
+ - Domain filter DSL — composable JSON expressions: `[field, op, value]`, `{"and": [...]}`, `{"or": [...]}`, `{"not": ...}`
20
+ - Full operator set: `=` `!=` `>` `<` `>=` `<=` `in` `not in` `like` `ilike` `is_null`
21
+ - Child field filtering via EXISTS subquery (dot notation: `"lines.quantity"`)
22
+ - Child field aggregation via LEFT JOIN (`"lines.quantity:sum"`)
23
+ - Date granularity grouping: `day` `week` `month` `quarter` `year`
24
+ - Aggregate functions: `count` `sum` `avg` `min` `max`
25
+ - HAVING filter on aggregate aliases
26
+ - Schema auto-derived from `inspect(model_class)` — O2M relationships are children by convention
27
+ - Sync (`Session`) and async (`AsyncSession`) APIs
28
+ - `QueryError` with `code` and `message` — field validation at compile time, before DB
29
+ - `py.typed` marker — PEP 561 inline type annotations
@@ -0,0 +1,64 @@
1
+ # Contributing to AxiomQuery
2
+
3
+ ## Setup
4
+
5
+ Requires Python 3.12+ and [uv](https://docs.astral.sh/uv/).
6
+
7
+ ```bash
8
+ git clone https://github.com/Axiom-Dev-Labs/AxiomQuery
9
+ cd AxiomQuery
10
+ uv sync
11
+ ```
12
+
13
+ ## Running tests
14
+
15
+ ```bash
16
+ uv run pytest
17
+ ```
18
+
19
+ The test suite uses SQLite in-memory — no external DB needed.
20
+
21
+ ## Project layout
22
+
23
+ ```
24
+ src/axiom_query/
25
+ errors.py QueryError
26
+ operators.py Op enum
27
+ ast.py Immutable AST nodes (Condition, And, Or, Not, Bool)
28
+ parser.py parse_domain() — JSON → AST
29
+ schema.py derive_schema() — ModelSchema from SA inspect()
30
+ compiler.py compile_domain() → SA WHERE ColumnElement
31
+ aggregation.py ReadGroupQuery AST nodes
32
+ aggregation_parser.py parse_read_group() — raw dict → ReadGroupQuery
33
+ compiler_aggregate.py compile_read_group() → SA SELECT
34
+ engine.py QueryEngine — public facade
35
+ tests/
36
+ conftest.py Order/OrderLine fixtures, SQLite engine
37
+ test_list.py list() / alist() tests
38
+ test_read_group.py read_group() tests
39
+ test_async.py async tests
40
+ examples/
41
+ example_sync.py Runnable sync walkthrough
42
+ example_async.py Runnable async walkthrough
43
+ ```
44
+
45
+ ## Adding a new operator
46
+
47
+ 1. Add the value to `Op` in `operators.py`
48
+ 2. Handle it in `_apply_operator()` in `compiler.py`
49
+ 3. Handle it in `_apply_having_operator()` if valid in HAVING context
50
+ 4. Add a test in `test_list.py`
51
+
52
+ ## Adding a new aggregate function
53
+
54
+ 1. Add the value to `AggFunc` in `aggregation.py`
55
+ 2. Handle it in `_compile_aggregate_column()` in `compiler_aggregate.py`
56
+ 3. Add a test in `test_read_group.py`
57
+
58
+ ## Release checklist
59
+
60
+ - [ ] Bump `version` in `pyproject.toml` and `__init__.py`
61
+ - [ ] Add entry to `CHANGELOG.md`
62
+ - [ ] Run full test suite: `uv run pytest`
63
+ - [ ] Build: `uv build`
64
+ - [ ] Publish: `uv publish`
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Axiom Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: AxiomQuery
3
+ Version: 0.1.0
4
+ Summary: Specification-based query and aggregation engine for SQLAlchemy 2.0 ORM models
5
+ Project-URL: Source Code, https://github.com/Axiom-Dev-Labs/AxiomQuery
6
+ Project-URL: Bug Tracker, https://github.com/Axiom-Dev-Labs/AxiomQuery/issues
7
+ Project-URL: Changelog, https://github.com/Axiom-Dev-Labs/AxiomQuery/blob/main/CHANGELOG.md
8
+ Author: Axiom Contributors
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Axiom Contributors
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: domain,filter,groupby,orm,query,specification,sqlalchemy
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Topic :: Database
38
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
39
+ Classifier: Typing :: Typed
40
+ Requires-Python: >=3.12
41
+ Requires-Dist: sqlalchemy>=2.0
42
+ Description-Content-Type: text/markdown
43
+
44
+ # AxiomQuery
45
+
46
+ Specification-based query and aggregation engine for SQLAlchemy 2.0 ORM models.
47
+
48
+ Define filters as composable data — JSON lists, dicts, or Python AST nodes — and execute them against any ORM model without writing raw SQL.
49
+
50
+ ---
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pip install AxiomQuery
56
+ ```
57
+
58
+ Requires Python 3.12+ and SQLAlchemy 2.0+.
59
+
60
+ ---
61
+
62
+ ## Quick start
63
+
64
+ ```python
65
+ from axiom_query import QueryEngine
66
+
67
+ engine = QueryEngine(Order) # inspect() once — no DB connection at construction
68
+
69
+ with Session(db) as session:
70
+ # list
71
+ records = engine.list(session, domain=[["status", "=", "CONFIRMED"]])
72
+
73
+ # read_group
74
+ groups, total = engine.read_group(
75
+ session,
76
+ groupby=["status"],
77
+ aggregates=["__count", "total:sum"],
78
+ )
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Domain filter syntax
84
+
85
+ A **domain** is a JSON-serialisable expression compiled to a WHERE clause at query time.
86
+
87
+ ### Condition tuple
88
+
89
+ ```python
90
+ [field_path, operator, value]
91
+ ```
92
+
93
+ | Operator | Meaning |
94
+ |----------|---------|
95
+ | `=` `!=` `>` `<` `>=` `<=` | Comparison |
96
+ | `in` `not in` | Membership (value is a list) |
97
+ | `like` `ilike` | Pattern match (`%` wildcard) |
98
+ | `is_null` | Null check (value is `True`/`False`) |
99
+
100
+ ### Logical composition
101
+
102
+ ```python
103
+ # AND — list of conditions (implicit)
104
+ [["status", "=", "CONFIRMED"], ["total", ">", 100]]
105
+
106
+ # AND — explicit
107
+ {"and": [["status", "=", "CONFIRMED"], ["total", ">", 100]]}
108
+
109
+ # OR
110
+ {"or": [["status", "=", "DRAFT"], ["status", "=", "CANCELLED"]]}
111
+
112
+ # NOT
113
+ {"not": ["status", "=", "CANCELLED"]}
114
+
115
+ # Combined — list mixes plain conditions with logical dicts
116
+ [
117
+ {"or": [["status", "=", "CONFIRMED"], ["status", "=", "DRAFT"]]},
118
+ {"not": ["total", "=", 0]},
119
+ ]
120
+ ```
121
+
122
+ ### Child field (EXISTS subquery)
123
+
124
+ Filter parent records by a child relationship field using dot notation. O2M relationships are automatically detected via `inspect()`.
125
+
126
+ ```python
127
+ # Orders that have at least one line with quantity > 2
128
+ engine.list(session, domain=[["lines.quantity", ">", 2]])
129
+ ```
130
+
131
+ ---
132
+
133
+ ## `list()` — filtered records
134
+
135
+ ```python
136
+ records = engine.list(
137
+ session,
138
+ domain=None, # domain expression or None (all records)
139
+ limit=None, # max records to return
140
+ offset=None, # records to skip
141
+ order_by=None, # [["field", "asc|desc"], ...]
142
+ )
143
+ # returns list[ORM model instances]
144
+ ```
145
+
146
+ ---
147
+
148
+ ## `read_group()` — grouped aggregation
149
+
150
+ ```python
151
+ groups, total = engine.read_group(
152
+ session,
153
+ groupby=["status", "created_at:month"], # field or field:granularity
154
+ aggregates=["__count", "total:sum"], # __count or field:func
155
+ domain=None, # WHERE filter
156
+ having=None, # HAVING filter on aggregate aliases
157
+ order_by=None, # [["alias", "asc|desc"], ...]
158
+ limit=None,
159
+ offset=None,
160
+ )
161
+ # returns (list[dict], int) — each dict includes a __domain key
162
+ ```
163
+
164
+ **Aggregate functions:** `count` `sum` `avg` `min` `max`
165
+
166
+ **Date granularities:** `day` `week` `month` `quarter` `year`
167
+
168
+ **Child aggregate** (LEFT JOIN):
169
+
170
+ ```python
171
+ engine.read_group(session, groupby=["status"], aggregates=["lines.quantity:sum"])
172
+ ```
173
+
174
+ **`__domain` drill-down** — each group result includes a `__domain` ready to pass back to `list()`:
175
+
176
+ ```python
177
+ groups, _ = engine.read_group(session, groupby=["status"], aggregates=["__count"])
178
+ for group in groups:
179
+ records = engine.list(session, domain=group["__domain"])
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Async API
185
+
186
+ Prefix any method with `a` and pass an `AsyncSession`:
187
+
188
+ ```python
189
+ engine = QueryEngine(Order)
190
+
191
+ async with AsyncSession(db) as session:
192
+ records = await engine.alist(session, domain=[["status", "=", "CONFIRMED"]])
193
+ groups, total = await engine.aread_group(session, groupby=["status"], aggregates=["__count"])
194
+ ```
195
+
196
+ ---
197
+
198
+ ## Schema derivation
199
+
200
+ `QueryEngine` derives its schema from `inspect(model_class)` at construction time — no separate descriptor needed:
201
+
202
+ - **Columns** → from `mapper.columns`
203
+ - **Child relations** → O2M relationships (`RelationshipDirection.ONETOMANY`) become filterable child entities
204
+ - **FK column** → resolved from `rel.synchronize_pairs`
205
+
206
+ ---
207
+
208
+ ## Error handling
209
+
210
+ Invalid field paths and unsupported operators raise `QueryError` before hitting the database:
211
+
212
+ ```python
213
+ from axiom_query import QueryError
214
+
215
+ try:
216
+ engine.list(session, domain=[["unknown_field", "=", "x"]])
217
+ except QueryError as e:
218
+ print(e.code, e.message) # INVALID_FILTER_FIELD No field 'unknown_field' ...
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Examples
224
+
225
+ Self-contained runnable examples in [`examples/`](examples/):
226
+
227
+ ```bash
228
+ python examples/example_sync.py
229
+ python examples/example_async.py
230
+ ```
231
+
232
+ Both cover: simple filters, AND / OR / NOT, combined nesting, child EXISTS filtering, pagination, `read_group` with domain / date granularity / child aggregation / HAVING, and `__domain` drill-down.