libvcs._internal.query_list#

Utilities for filtering or searching list of objects / list data.

Note

This is an internal API not covered by versioning policy.

libvcs._internal.query_list.LOOKUP_NAME_MAP#
class libvcs._internal.query_list.LookupProtocol#

Protocol for QueryList filtering operators.

class libvcs._internal.query_list.QueryList#

Filter list of object/dicts. For small, local datasets. Experimental, unstable.

>>> query = QueryList(
...     [
...         {
...             "place": "Largo",
...             "city": "Tampa",
...             "state": "Florida",
...             "foods": {"fruit": ["banana", "orange"], "breakfast": "cereal"},
...         },
...         {
...             "place": "Chicago suburbs",
...             "city": "Elmhurst",
...             "state": "Illinois",
...             "foods": {"fruit": ["apple", "cantelope"], "breakfast": "waffles"},
...         },
...     ]
... )
>>> query.filter(place="Chicago suburbs")[0]['city']
'Elmhurst'
>>> query.filter(place__icontains="chicago")[0]['city']
'Elmhurst'
>>> query.filter(foods__breakfast="waffles")[0]['city']
'Elmhurst'
>>> query.filter(foods__fruit__in="cantelope")[0]['city']
'Elmhurst'
>>> query.filter(foods__fruit__in="orange")[0]['city']
'Tampa'
data#
filter(self, matcher=None, **kwargs)#
Parameters:

matcher (Optional[Union[Callable[[T], bool], T]]) –

items(self)#
libvcs._internal.query_list.T#
libvcs._internal.query_list.keygetter(obj, path)#

obj, “foods__breakfast”, obj[‘foods’][‘breakfast’]

>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods__breakfast")
'cereal'
>>> keygetter({ "foods": { "breakfast": "cereal" } }, "foods")
{'breakfast': 'cereal'}
libvcs._internal.query_list.lookup_contains(data, rhs)#
libvcs._internal.query_list.lookup_endswith(data, rhs)#
libvcs._internal.query_list.lookup_exact(data, rhs)#
libvcs._internal.query_list.lookup_icontains(data, rhs)#
libvcs._internal.query_list.lookup_iendswith(data, rhs)#
libvcs._internal.query_list.lookup_iexact(data, rhs)#
libvcs._internal.query_list.lookup_in(data, rhs)#
libvcs._internal.query_list.lookup_iregex(data, rhs)#
libvcs._internal.query_list.lookup_istartswith(data, rhs)#
libvcs._internal.query_list.lookup_nin(data, rhs)#
libvcs._internal.query_list.lookup_regex(data, rhs)#
libvcs._internal.query_list.lookup_startswith(data, rhs)#
libvcs._internal.query_list.parse_lookup(obj, path, lookup)#

Check if field lookup key, e.g. “my__path__contains” has comparator, return val.

If comparator not used or value not found, return None.

mykey__endswith(“mykey”) -> “mykey” else None

>>> parse_lookup({ "food": "red apple" }, "food__istartswith", "__istartswith")
'red apple'