Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

py-predicate

Latest version: v1.12.0

Overview

Last scanned
29 Nov 2026
Published
29 Nov 2026
PyPI package Publisher: mrijk
10 Stars
5 Forks
4 Versions
19 Downloads
Python Repo language

Scan summary

py-predicate was last scanned on 29 Nov 2026 at version 1.12.0. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 4 versions; the latest was published on 29 Nov 2026.
  • Findings: No rules fired in version 1.12.0.
  • Downloads: 19 downloads.

Versions

4 versions published
Versions and the rules that fired in each
VersionPublishedStatus
1.12.0 LATEST 29 Nov 2026 No rules fired
1.11.0 8 Nov 2026 No rules fired
1.10.0 26 Oct 2026 No rules fired
1.9.0 15 Oct 2026 Not shown

No rules fired in 1.12.0

Findings

Findings for v1.12.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 1.12.0; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

Documentation Test

py-predicate

A typed Python library for composable predicates.

Predicates are first-class objects that can be combined with boolean operators, optimized algebraically, compiled to native callables for performance, serialized to multiple formats, and used to instrument functions with runtime contracts.

Full documentation: mrijk.github.io/py-predicate

Installation

pip install py-predicate

Quick start

from predicate import ge_p, le_p

ge_2 = ge_p(2)
le_5 = le_p(5)

between = ge_2 & le_5

between(3)  # True
between(7)  # False

filtered = [x for x in range(10) if between(x)]  # [2, 3, 4, 5]

Predicates compose with standard Python operators:

Operator Meaning
p & q both must hold (AndPredicate)
p \| q either must hold (OrPredicate)
p ^ q exactly one must hold (XorPredicate)
~p negation (NotPredicate)

Built-in predicates

Comparisons: eq_p, ne_p, gt_p, ge_p, lt_p, le_p, is_close_p

Ranges: ge_le_p, ge_lt_p, gt_le_p, gt_lt_p (compiled to chained comparisons)

Type checks: is_int_p, is_str_p, is_float_p, is_bool_p, is_list_p, is_dict_p, is_none_p, is_not_none_p, is_instance_p, and many more

Collections: all_p, any_p, in_p, not_in_p, has_length_p, is_empty_p, is_not_empty_p, has_key_p, has_path_p

Typed collections: is_list_of_p, is_set_of_p, is_dict_of_p, is_tuple_of_p

Strings: regex_p, starts_with_p, ends_with_p, is_alpha_p, is_digit_p, is_int_str_p, is_upper_p, is_lower_p, and more

Logic: always_p, never_p, implies_p, fn_p

non_neg_p and non_pos_p include zero and compose the existing ge_p(0) and le_p(0) comparisons.

Numeric: is_even_p, is_odd_p, is_nan_p, is_inf_p, is_finite_p, pos_p, neg_p, non_neg_p, non_pos_p, zero_p

Failure explanation

Use explain to get a structured description of why a predicate failed:

from predicate import explain, ge_p, le_p

between = ge_p(2) & le_p(5)
explain(between, 8)
# {'reason': 'Right predicate failed', 'right': {'reason': 'Expected 8 <= 5'}}

Optimizer

Predicate trees can be algebraically simplified:

from predicate import ge_p, le_p, optimize, can_optimize

p = ge_p(2) & le_p(5)
can_optimize(p)  # True (may simplify to a range predicate, etc.)
optimized = optimize(p)

The optimizer handles identities like p & always_true == p, p | always_true == always_true, double-negation elimination, De Morgan's laws, and more.

Compile to native callables

compile_predicate translates a predicate tree into a native Python lambda via AST generation, removing interpreter overhead on hot paths:

from predicate import compile_predicate, ge_p, le_p

between = ge_p(2) & le_p(5)
fast = compile_predicate(between)  # returns a CompiledPredicate

fast(3)  # True  — evaluated by a native lambda: lambda x: x >= 2 and x <= 5
fast(8)  # False

# Introspection is preserved
repr(fast)  # same as repr(between)
fast.explain_failure  # delegates to the original predicate

Use try_compile_predicate to fall back to the original when compilation is not supported (e.g. fn_p, regex_p):

from predicate import try_compile_predicate

safe = try_compile_predicate(some_predicate)  # always returns a callable

Value generation

Predicates can drive property-based testing by generating values that satisfy or violate them:

from predicate import generate_true, generate_false, ge_p, le_p
from more_itertools import take

between = ge_p(2) & le_p(5)

take(5, generate_true(between))  # e.g. [2, 3, 4, 5, 2]
take(5, generate_false(between))  # e.g. [0, 1, 6, 7, -1]

Pydantic integration

With the optional extra (pip install py-predicate[pydantic]), a predicate can validate a Pydantic v2 field, after the inner type's own validation:

from typing import Annotated

from pydantic import BaseModel

from predicate import ge_p, lt_p
from predicate.pydantic import PredicateValidator


class Model(BaseModel):
    x: Annotated[int, PredicateValidator(ge_p(0) & lt_p(100))]

A failure raises a predicate_failed error whose context holds the predicate and its explain_failure result. Comparisons, eq_p, in_p, &, |, ~, all_p, any_p and regex_p also appear in the JSON Schema of the field (predicate_to_json_schema).

Hypothesis integration

With the optional extra (pip install py-predicate[hypothesis]), predicates can be used as Hypothesis strategies:

from predicate import ge_p, lt_p
from predicate.hypothesis import from_predicate, given_predicate


@given_predicate(ge_p(0) & lt_p(100))
def test_something(x):
    assert 0 <= x < 100


from_predicate(ge_p(0) & lt_p(100))  # a regular SearchStrategy

Numeric bounds are merged into a single native strategy. Predicates without a dedicated mapping are generated from their type and filtered.

A Spec can drive a property test too. given_spec calls the function with generated arguments and checks the result against ret, fn, fn_p and raises, with Hypothesis' shrinking and replay. from_spec returns just the strategy of arguments:

from predicate import ge_p, is_int_p
from predicate.hypothesis import from_spec, given_spec


def add(x, y):
    return x + y


spec = {"args": {"x": ge_p(0), "y": is_int_p}, "ret": is_int_p}

test_add = given_spec(add, spec)  # pytest collects this; or call test_add() directly
arguments = from_spec(add, spec)  # strategy of {"x": ..., "y": ...} dicts

Plain functions only for now: async functions, generators and classes aren't supported yet.

pytest integration

The separate pytest-predicate package (pip install pytest-predicate) provides assertion helpers (assert_matches, assert_not_matches) and a predicate_examples fixture that generates matching and non-matching values.

Recursive predicates

Use root_p (or this_p) to define self-referencing predicates over arbitrarily nested structures without writing recursive functions:

from predicate import all_p, is_list_p, is_str_p, root_p

# Matches a string, or a list of strings/lists (recursively)
str_or_nested = is_str_p | (is_list_p & all_p(root_p))

str_or_nested("hello")  # True
str_or_nested(["a", ["b", "c"]])  # True
str_or_nested(["a", 1])  # False

Use recur_p for predicates over a sequence, where each element is checked against the one before it:

from predicate import ge_p, recur_p

is_sorted = recur_p(ge_p)  # each element >= the previous one

is_sorted([1, 2, 2, 5])  # True
is_sorted([3, 1])  # False
is_sorted([])  # True, use empty=False to reject empty input

For mutually recursive predicates, use mutual_recur_p.

Runtime instrumentation (Spec)

Instrument functions with predicate-based contracts that are checked at call time:

from predicate import ge_p, instrument, is_int_p, is_str_p, le_p


@instrument({"args": {"x": is_int_p & ge_p(0) & le_p(100)}, "ret": is_str_p})
def grade(x: int) -> str:
    return "pass" if x >= 50 else "fail"


grade(75)  # "pass"
grade(-1)  # raises SpecViolationError: Parameter predicate for parameter 'x' of function grade failed

You can also instrument all functions in a module or class:

from predicate import instrument_module, instrument_class

instrument_module(my_module)
instrument_class(MyClass)

Specs can include cross-argument constraints via fn or fn_p keys, and expected exception types via raises.

To turn all checks off without removing the decorators, set PREDICATE_INSTRUMENT=0 or call set_instrumentation(False).

Analysis

Check logical properties of predicates:

from predicate import are_equivalent, is_satisfiable, is_tautology, ge_p, le_p, always_p

is_tautology(always_p)  # True
is_satisfiable(ge_p(5) & le_p(3))  # False (unsatisfiable)
are_equivalent(~~ge_p(2), ge_p(2))  # True

Serialization

Export predicates to multiple formats:

from predicate import ge_p, le_p, to_json, to_yaml, to_dot, to_latex

p = ge_p(2) & le_p(5)

to_json(p)  # JSON string
to_yaml(p)  # YAML string
to_dot(p)  # Graphviz DOT for visualization (requires `pip install py-predicate[graphviz]`)
to_latex(p)  # LaTeX expression

Deserialize from JSON:

from predicate.formatter.from_json import from_json

p = from_json('{"and": [{"ge": 2}, {"le": 5}]}')

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases py-predicate

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

PolinRider Returns
Research

PolinRider Returns: Hijacked npm Packages Use Ethereum Blockchain to Conceal Malware Infrastructure

Critical Apache HTTP Server Flaw Exposes Web Servers to RCE (1)
CVE

CVE-2026-119618: Critical Apache HTTP Server Flaw Exposes Web Servers to Remote Code Execution

Frame 2085668439 (1)
Group 1261154229