gramps-object-query-language
A small, closed query AST and SQL compiler for fast object queries against Gramps genealogy data.
This is not a general query language, not GraphQL, and not a raw-SQL
passthrough. It compiles a structured Query (select/where/order_by/
limit/after) -- or an "almost Python" expression string -- into
parameterized SQL against Gramps' flattened secondary columns, with every
column checked against a fixed per-type whitelist before the compiler ever
touches it.
Paths into the JSON blob are checked, not trusted: every Gramps class
publishes a complete recursive get_schema(), so
primary_name.surname_list[0].surname is whitelisted the same way a flat
column name is, and a typo is a compile-time error naming the fields that
exist rather than an all-NULL column.
It is standalone and privacy-agnostic: it carries no knowledge of proxies,
permissions, or any particular web API. An evaluator/proxied_query path
is also included for evaluating the same query AST directly against real
(possibly proxied) Gramps objects, for callers that can't run raw SQL
against an unproxied database.
Install
pip install gramps-object-query-language
Documentation
README-query-language.md-- a plain-language, goal-first guide towhere_exprfor non-programmers ("Find all the families where the mom died before the dad" -> the query for it).docs/where_expr.md-- the technical reference for the "almost Python"where_exprfilter language (Person "gender == Person.MALE",Family "mother.death.date.sortval < father.death.date.sortval", ...), with every example tested against real SQLite.
Modules
gramps_object_query_language.query-- the query AST and SQL compiler.gramps_object_query_language.query_lang-- an "almost Python" expression parser (parse_expr) that translates into the samewhereshape, pluscompile_expr, which translates it the rest of the way intoquery.py's executable AST for callers that want to run it directly, andparse_select, which parsesselectentries ("birth.place.title as birthplace","count(events) as n_events") written in that same path grammar. Seedocs/where_expr.md.gramps_object_query_language.evaluator-- evaluates the AST directly against real Gramps objects (no SQL), for use with a proxied database.gramps_object_query_language.proxied_query-- runs awhereexpression through Gramps' ownFilter/Rulemachinery against a possibly-proxied database.
Benchmarks
benchmarks/sort_cost.py measures what each kind of sort column costs
(indexed flat column vs. JSON path vs. relationship hop), with SQLite's own
query plans. Its output is quoted in
docs/where_expr.md -- run it
rather than trusting the numbers there.
python benchmarks/sort_cost.py --people 20000
Development
pip install -e ".[test]"
pytest
License
GNU Affero General Public License v3 or later (AGPL-3.0-or-later). See LICENSE.
Release files for gramps-object-query-language 0.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gramps_object_query_language-0.5.3.tar.gz | 88.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gramps_object_query_language-0.5.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 180.7 kB
Release files / gramps_object_query_language-0.5.3.tar.gz
| Download URL | gramps_object_query_language-0.5.3.tar.gz |
|---|---|
| Size | 88.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ddca4e8b64b974c4b4e92915b1dcad62cae678bc79c346ae05ec1b6b66aafba3
|
|
BLAKE2b-256 checksum How to use checksums |
5d0273399d3e667f4558101b878fe922bed6b43559b6c351cb4a5ccf33daeee6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|
Release files / gramps_object_query_language-0.5.3-py3-none-any.whl
| Download URL | gramps_object_query_language-0.5.3-py3-none-any.whl |
|---|---|
| Size | 92.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
96e6f868f98545e63e2eac3c535632cf19ec7d217b4c968ef9ebbb7d79b44d94
|
|
BLAKE2b-256 checksum How to use checksums |
9dcc5d511405622daf93897d36b1f751e3de078038cf309346110867f98863ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|