Skip to main content

Predicates for Python.

Project description

Predicates for Python

Library for constuction predicates like (OwnedBy('alex') | OwnedBy('alice')) & HasTag('game-design') and applying them to other objects.


I tired from reimplementation of custom predicate logic in my pet projects. So, I implemented that library.

Library focus on usability, not performance. At least, for now.


pip install pydicates


Minimal example

from pydicates import Predicate, common

def HasTag(tag):
    return Predicate('has_tag', tag)

def has_tag(context, tag, document):
    return tag in document['tags']

common.register('has_tag', has_tag)

document = {'tags': ('a', 'b', 'c', 'd')}

assert common(HasTag('a') & HasTag('c'), document)
assert not common(HasTag('a') & HasTag('e'), document)
assert common(HasTag('a') & ~HasTag('e'), document)
assert common(HasTag('a') & (HasTag('e') | HasTag('d')), document)

More examples can be found in ./examples directory.

See ./examples/ for API description.

See ./tests for more examples.


  • Can not chain redefined comparisons: a < b < c is equal to (a < b) and (b < c) which translates by Python to b < c, because a < b is object (Predicate) and always True.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pydicates, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size pydicates-0.1.1-py3-none-any.whl (6.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pydicates-0.1.1.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page