← Back to all products
$29
Conditional Logic Engine
Dynamic form behavior with 15 operators and 9 action types for show/hide/require/skip fields.
JSONMarkdownPython
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 10 files
conditional-logic-engine/
├── LICENSE
├── README.md
├── examples/
│ └── form_rules.json
├── free-sample.zip
├── guide/
│ ├── 01_features.md
│ ├── 02_cli-reference.md
│ ├── 03_programmatic-usage.md
│ └── 04_license.md
├── index.html
└── src/
└── conditional_logic_engine.py
📖 Documentation Preview README excerpt
Conditional Logic Engine
Dynamic form behavior with 15 operators and 9 action types — show, hide, require, skip fields based on user input. Pure Python, zero dependencies.
Part of the [Form Forge](https://form-forge.codevault.dev) toolkit by CodeVault.
Features
- 15 comparison operators: equals, not_equals, greater_than, less_than, greater_equal, less_equal, contains, not_contains, starts_with, ends_with, is_empty, is_not_empty, matches (regex), in, not_in
- 9 action types: show, hide, require, optional, skip, set_value, validate, disable, enable
- JSON rule definitions: define all logic in a declarative JSON format
- AND/OR logic groups: combine multiple conditions with boolean operators
- Field-to-field references: conditions can reference other form field values
- Evaluation engine: evaluate rules against live form data and return actions to execute
- Python 3.10+ stdlib only — no pip installs required
Quick Start
# Evaluate rules against form data
python src/conditional_logic_engine.py --rules examples/form_rules.json --data '{"country": "US", "age": "25"}'
# Run the built-in demo
python src/conditional_logic_engine.py --demo
CLI Reference
| Flag | Description |
|---|---|
--rules FILE | JSON file containing conditional logic rules |
--data JSON | Form data as a JSON string to evaluate against |
--demo | Run a built-in demo showing all operator/action types |
Rules JSON Format
{
"rules": [
{
"id": "show-company-field",
"description": "Show company name when role is Business",
"logic": "and",
"conditions": [
{
"field": "role",
"operator": "equals",
"value": "business"
}
],
"actions": [
{
"type": "show",
"target": "company_name"
},
{
"type": "require",
"target": "company_name"
}
]
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/conditional_logic_engine.py
#!/usr/bin/env python3
"""
Conditional Logic Engine — Dynamic Form Rules
===============================================
Define show/hide rules, skip conditions, dynamic validation,
and field dependencies using a declarative JSON-based rule engine.
Evaluates conditions at runtime and outputs the active field set.
Part of the Form Forge toolkit by DataNest.
License: MIT
"""
from __future__ import annotations
import argparse
import json
import logging
import operator
import re
import sys
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Callable
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
# ---------------------------------------------------------------------------
# Constants & operator map
# ---------------------------------------------------------------------------
OPERATOR_MAP: dict[str, Callable[[Any, Any], bool]] = {
"equals": operator.eq,
"not_equals": operator.ne,
"greater_than": operator.gt,
"less_than": operator.lt,
"greater_equal": operator.ge,
"less_equal": operator.le,
"contains": lambda a, b: str(b).lower() in str(a).lower(),
"not_contains": lambda a, b: str(b).lower() not in str(a).lower(),
"starts_with": lambda a, b: str(a).lower().startswith(str(b).lower()),
"ends_with": lambda a, b: str(a).lower().endswith(str(b).lower()),
"is_empty": lambda a, _: not str(a).strip(),
"is_not_empty": lambda a, _: bool(str(a).strip()),
"matches": lambda a, b: bool(re.match(str(b), str(a))),
"in": lambda a, b: str(a) in (b if isinstance(b, list) else str(b).split(",")),
"not_in": lambda a, b: str(a) not in (b if isinstance(b, list) else str(b).split(",")),
}
class ActionType(Enum):
# ... 386 more lines ...