Skip to main content

Predicates for Python

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

Motivation

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.

Install

pip install pydicates

Use

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/documents_check.py for API description.

See ./tests for more examples.

Limitations

  • 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.

Metadata

Release files for pydicates 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydicates 0.1.1
File Size Uploaded Provenance Actions
pydicates-0.1.1.tar.gz 5.2 kB Without provenance Details for pydicates-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydicates 0.1.1
File Interpreter ABI Platform Actions
pydicates-0.1.1-py3-none-any.whl Python 3 none any Details for pydicates-0.1.1-py3-none-any.whl

Total release size: 11.2 kB

Release files / pydicates-0.1.1.tar.gz

Download URL pydicates-0.1.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
400e9eca362ee9354504cd3295a9e103573adb971e22fbf6f046973e4edc229a
BLAKE2b-256 checksum
How to use checksums
19e1d688bd022af2e9ddf2ead6a06569cd9d9b9a53ae47f1be92839dc0a2f191
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-72-generic

Release files / pydicates-0.1.1-py3-none-any.whl

Download URL pydicates-0.1.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fd819985839ba5535ea8a296c0a64a14a414ab68b0864a21f3e281d7b607f7d
BLAKE2b-256 checksum
How to use checksums
c7fa5c22543b297f2f5ccb5c8aa27c28526c98f4e5379632533ad0323e02b999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.4 Linux/5.4.0-72-generic

Security for pydicates 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page