It'll defeat anything my editor can predict, making typos easier. It also makes it harder to reason about types, as I have to trust the library to make the right assumption. [0]
Instead of:
dq.match(data, "`friends.age` <= 26")
Why not:
import operator # from the standard library
dq.match(data, "friends.age", operator.le, 26)
It'll simplify your parsing, works with my editor, and makes it easier to reason about types. You'll still need to parse, as you're basically handling a variadic function, but the user can hand you an AST.
---
[0] For example, what type would occur if:
dq.match(data, "`friends.age` <= 26.")
Does 26 become a float? Or an integer? Or raise a ParseError?
I have to consider that with a string, less so with Python's own objects.
> The plus of "stringly API" is that you can save your queries in database, or get it through web interface
You can do the same with a function call, there's no difference, apart from already having a list of arguments to pass around. (And of course, the type uncertainty you get with a value stored in a string.)
> if you need a nested key value, you can use function:
Not sure why you're telling me that. What part of my comment are you responding to?
I'd prefer no quotes, but that would restrict the dictionary to keys without spaces. Maybe square brackets, since anyone using python already types those to access dictionary keys.
maybe even more simple than reinventing a langage using lambda functions applying on path/value in a dict with an iterator (which can be consumed by filter/any/map/reduce)
http://vectordict.readthedocs.io/en/latest/finding.html
As exercise I implemented a library to query dicts.
This is my first python library and I'm looking for feedback and criticism
Especially, I need advice about public API
https://github.com/cyberlis/dictquery
You can install it with:
pip install dictquery
To write it I read:
Python Cookbook third edition. 2.18 Tokenizing Text, 2.19 Writing a Simple Recursive Descent Parser
All parsing related articles from https://eli.thegreenplace.net/2010/01/02/top-down-operator-p...
https://docs.python.org/3/library/re.html#writing-a-tokenize...