I'm not the author, but this implementation has the benefit of being a JSON compatible DSL that you can serialize. Maybe that's intentional, maybe not.
It does look like Python's comprehensions would be a better choice if you're writing them by hand anyway.
Yea, In my opinion using Python's list comprehension is more readable and code checkable.
Here's the usage example from the README:
from leopards import Q
l = [{"name":"John","age":"16"}, {"name":"Mike","age":"19"},{"name":"Sarah","age":"21"}]
filtered= Q(l,{'name__contains':"k", "age__lt":20})
print(list(filtered))
Versus:
[x for x in l if ('k' in x['name'] and int(x['age']) < 20)]
Outputs:
[{'name': 'Mike', 'age': '19'}]
Also from the readme:
> Even though, age was str in the dict, as the value of in the query dict was int, Leopards converted the value in dict automatically to match the query data type. This behaviour can be stopped by passing False to convert_types parameter.
It does look like Python's comprehensions would be a better choice if you're writing them by hand anyway.