I recently saw that @DavidMStraub had created a project call Gramps Query Language, and it is even included in gramps-web. A query language is a good idea, but I found the Jira-inspired GQL not very intuitive, and has lots of builtin things (strings and field names look the same), and many loose ends.
I wondered why not use the language that at least many Gramps developers already use: Python! Many devs would be able to help construct queries.
I made a drop-in replacement for GQL. I call it “Pythonish QL” because I thought we might want (or need) to alter the Python syntax a little. But after a few revisions, no syntax needed to be changed.
So, I made a system that uses Gramps objects, with some clever items pre-defined in the query environment. I also liked @emyoulation 's suggestion to include the SimpleAccess API. I also used many of @DavidMStraub 's ideas and test suite (adapted).
So here are some examples:
Select all people married to someone named “Donna”:
sa.first_name(sa.spouse(person)) == "Donna"
Select all people with a note:
person.get_note_list()
A complicated one: find all of the people who have the word “vote” in a note:
any([('vote' in str(get_note(handle).text)) for handle in person.get_note_list()])
It should be possible to access all data in gramps, because we use the standard library.
It might be a little faster than GQL because the raw gramps data is not converted into objects, then dictionaries, and then back to objects (if needed). The query is also compiled, and uses eval()
.
I don’t think there are any security issues using eval() on these expressions. But if there are, we can do a couple of additional items to lock that down.
You can install it, or check it out:
- GitHub - dsblank/pythonish-ql: A Python-like language for querying JSON data
pip install pythonish-ql
Let me know what you think.