predicate

URL:

Pypi: https://pypi.org/project/predicate/

Gitlab: https://gitlab.com/mc706/predicate

Description

Predicate takes the django queryset filtering language and applies it to building python native predicate functions that you can pass to the filter builtin.

This library is mean to make creating native python filter functions readable and easy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
>>> from predicate import where

>>> people = [
... {'name': {'first': 'Joe', 'last': 'Smith'}, 'age': 25},
... {'name': {'first': 'Jane', 'last': 'Smith'}, 'age': 27},
... {'name': {'first': 'John', 'last': 'Smith'}, 'age': 33},
... {'name': {'first': 'Bill', 'last': 'Bob'}, 'age': 40},
... {'name': {'first': 'Joe', 'last': 'Bob'}, 'age': 59},
... ]


>>> young_smiths = list(filter(where(name__last__iexact='smith', age__lte=30), people))

>>> young_smiths
[{'name': {'first': 'Joe', 'last': 'Smith'}, 'age': 25}, {'name': {'first': 'Jane', 'last': 'Smith'}, 'age': 27}]

Technologies

  • Python
  • Functional Composition
  • Enums (for lack of ADTs in Python)

Setup

1
$ pip install predicate

Documentation

ReadTheDocs