Metadata-Version: 2.4
Name: vcti-predicate
Version: 2.0.1
Summary: VCollab Predicate - condition evaluation engine with extensible operators and modifiers
Author: Visual Collaboration Technologies Inc.
License-Expression: LicenseRef-Proprietary
Project-URL: Repository, https://github.com/vcollab/vcti-python-predicate
Project-URL: Changelog, https://github.com/vcollab/vcti-python-predicate/blob/main/CHANGELOG.md
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: lint
Requires-Dist: ruff; extra == "lint"
Provides-Extra: typecheck
Requires-Dist: mypy; extra == "typecheck"
Dynamic: license-file

# vcti-predicate

VCollab Predicate - condition evaluation engine with extensible operators and modifiers

## Overview

Filtering, validation, workflow conditionals and routing logic all need
to evaluate conditions such as "is this value greater than X?", "does
this string contain Y?" or "is Z in this list?". `vcti-predicate` provides
two entry points, `check()` and `evaluate()`, that take a *symbol*
(`"=="`, `"^="`, `"is_empty"`) and pick the comparison by the type of
the left-hand operand. Each operator belongs to a *group* that normalizes
its operands (strings compare case-insensitively by default) and declares
the modifiers it accepts (`case_sensitive`, `tolerance`, `inclusive`).
Symbols, operators and groups live in a registry you can extend or copy.

---

## Installation

```bash
pip install vcti-predicate
```

### In `requirements.txt`

```
vcti-predicate>=2.0.1
```

### In `pyproject.toml` dependencies

```toml
dependencies = [
    "vcti-predicate>=2.0.1",
]
```

---

## Quick Start

```python
from vcti.predicate import check

# ── Binary: check(lhs, symbol, rhs) ──

# String (case-insensitive by default)
check("Hello", "==", "hello")         # True
check("filename.pdf", "$=", "pdf")    # True
check("filename", "?=", "name")       # True

# Integer (exact)
check(5, ">", 3)     # True
check(5, "==", 5)    # True

# Float (with tolerance)
check(1.0, "==", 1.001, tolerance=0.01)   # True

# Case-sensitive via modifier or suffix
check("Hello", "==", "hello", case_sensitive=True)  # False
check("Hello", "^=cs", "Hello")                     # True

# Collection operations
check(2, "@=", [1, 2, 3])                  # True
check(["a", "b"], "all", ["a", "b", "c"])  # True

# Regex matching with options
check("test123", "~=", r"\d+")                          # True
check("line1\nline2", "~=", r"^line2", multiline=True)  # True

# Negation
check("hello", "!^=", "xyz")    # True (does not start with)
check("hello", "!~=", r"\d+")   # True (no digits)
check(4, "!@=", [1, 2, 3])     # True (not in list)

# Range (rhs is a (lo, hi) pair: tuple, list, or any two-element iterable)
check(5, "between", (1, 10))       # True
check(0, "!between", (1, 10))      # True

# ── Unary: check(value, symbol) ──

check("", "is_empty")           # True
check(None, "exists")           # False
check("/tmp/f.txt", "is_file")  # True (if file exists)
check("/tmp", "is_dir")         # True (if directory exists)
```

---

## Entry Points

| Function | Argument order | Use case |
|----------|---------------|----------|
| `check(lhs, op, rhs?)` | Value-first | Primary user-facing function — binary and unary |
| `evaluate(op, lhs, rhs?)` | Symbol-first | For rule engines and programmatic use |

Both use the same resolution, normalization, and dispatch engine.

---

## Symbol Summary

### Comparison

| Symbol | Alias | Description |
|--------|-------|-------------|
| `==` | `eq` | Equal |
| `!=` | `ne` | Not equal |
| `<` `<=` `>` `>=` | `lt` `le` `gt` `ge` | Ordering |

### String

| Symbol | Alias | Negation | Description |
|--------|-------|----------|-------------|
| `^=` | `startswith` | `!^=` | Starts with |
| `$=` | `endswith` | `!$=` | Ends with |
| `?=` | `contains` | `!?=` | Contains |
| `@=` | `in` | `!@=` | In collection/string |

### Regex

| Symbol | Alias | Negation | Description |
|--------|-------|----------|-------------|
| `~=` | `matches` | `!~=` | Regex search |

### Unary

| Symbol | Description |
|--------|-------------|
| `is_empty` / `exists` / `is_numeric` | Value checks |
| `is_file` / `is_dir` / `path_exists` | Filesystem checks |

### Range

| Symbol | Description |
|--------|-------------|
| `between` / `!between` | Value within bounds (rhs is a `(lo, hi)` pair) |

### Modifier Suffixes

Append `cs` or `ic` to string symbols for case control:
`^=cs`, `$=ic`, `?=cs`, `@=ic`, `~=cs`. A suffix fixes the case
handling, so it cannot be combined with the `case_sensitive` modifier.

For the complete symbol reference, see the
[Symbol Reference](docs/symbols.md).

---

## Modifiers

Pass modifiers as keyword arguments to control behavior:

```python
check("Hello", "==", "hello", case_sensitive=True)   # False
check(1.0, "==", 1.001, tolerance=0.01)              # True
check(5, "between", (1, 10), inclusive=False)         # True
check("text", "~=", r"^line", multiline=True)        # regex option
```

| Modifier | Type | Groups | Default | Effect |
|----------|------|--------|---------|--------|
| `case_sensitive` | `bool` | string, collection, regex | `False` | Case-sensitive comparison |
| `tolerance` | `float` (`int` accepted) | float | `0.0` | Maximum absolute difference for equality (float LHS only; finite, `>= 0`) |
| `inclusive` | `bool` | range | `True` | Include bounds in range check |
| `multiline`, `dotall` | `bool` | regex operators (options) | `False` | `re.MULTILINE` / `re.DOTALL` |

Values are checked against the declared type, so `case_sensitive="false"`
raises `TypeError` instead of being read as true. Types no group handles
(lists, `None`, dates, ...) compare with plain Python operators and accept
no modifiers.

---

## Dependencies

None. `vcti-predicate` uses only the Python standard library.

---

## Documentation

| If you want to… | Read |
|---|---|
| Get started using the package | Quick Start above |
| Look up every symbol and which types it supports | [docs/symbols.md](docs/symbols.md) |
| See practical, real-world usage | [docs/patterns.md](docs/patterns.md) |
| Understand the architecture and design decisions | [docs/design.md](docs/design.md) |
| Navigate and understand the source | [docs/source-guide.md](docs/source-guide.md) |
| Extend the library with operators, groups and symbols | [docs/extending.md](docs/extending.md) |
