pydantic-logic


Namepydantic-logic JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/barabum0/pydantic-logic
SummaryDescription
upload_time2024-11-26 14:57:34
maintainerNone
docs_urlNone
authorRoman Poltorabatko
requires_python<4.0,>=3.10
licenseMIT
keywords python pydantic logic condition validation json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <h1>pydantic-logic</h1>
  <p>
    <img alt="License: MIT" src="https://img.shields.io/github/license/barabum0/pydantic-logic">
    <img alt="GitHub stars" src="https://img.shields.io/github/stars/barabum0/pydantic-logic">
    <a href="https://pypi.org/project/pydantic-logic">
        <img alt="PyPI version" src="https://img.shields.io/pypi/v/pydantic-logic.svg?logo=pypi&logoColor=FFE873">
    </a>
    <a href="https://github.com/psf/black">
        <img alt="code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
    </a>
    <a href="https://github.com/PyCQA/isort">
        <img alt="formatted with: isort" src="https://img.shields.io/badge/formatted%20with-isort-blue.svg">
    </a>
    <a href="https://mypy-lang.org/">
        <img alt="mypy: checked" src="https://www.mypy-lang.org/static/mypy_badge.svg">
    </a>
  </p>
</div>
Build complex rules, operate them with Pydantic, and execute them in Python

## Installation
```shell
pip install pydantic-logic
```

## Examples

### True expression
```python
from pydantic_logic import Logic, LogicExpression, Operator

data = {
    "Phone number": "123123123",
    "some_value": True,
    "some_other_value": 1,
}

logic = Logic(
    expressions=[
        LogicExpression.b("Phone number", Operator.NE, "adasdasdasd"),
        LogicExpression.b("some_value", Operator.EQ, True),
        LogicExpression.b("some_other_value", Operator.GT, 0),
    ]
)
assert logic.evaluate(data)
```

### False expression
```python
from pydantic_logic import Logic, LogicExpression, Operator

data = {
    "Phone number": "123123123",
    "some_value": True,
    "some_other_value": 1,
}

logic = Logic(
    expressions=[
        LogicExpression.b("Phone number", Operator.EQ, "123123123"),
        LogicExpression.b("some_value", Operator.NE, False),
        LogicExpression.b("some_other_value", Operator.LT, 1),
    ]
)
assert not logic.evaluate(data)
```

### Empty expression with default result
Suitable if the expressions are set by the end users, not the code
```python
from pydantic_logic import Logic

data = {
    "Phone number": "123123123",
    "some_value": True,
    "some_other_value": 1,
}

logic = Logic(
    expressions=[]
)
assert logic.evaluate(data, default_if_empty=True)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/barabum0/pydantic-logic",
    "name": "pydantic-logic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "python, pydantic, logic, condition, validation, json",
    "author": "Roman Poltorabatko",
    "author_email": "r.m.poltorabatko@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/d4/0f81712220122b28c086f6856ac784479838de3506d4987f943bb1279379/pydantic_logic-1.0.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <h1>pydantic-logic</h1>\n  <p>\n    <img alt=\"License: MIT\" src=\"https://img.shields.io/github/license/barabum0/pydantic-logic\">\n    <img alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/barabum0/pydantic-logic\">\n    <a href=\"https://pypi.org/project/pydantic-logic\">\n        <img alt=\"PyPI version\" src=\"https://img.shields.io/pypi/v/pydantic-logic.svg?logo=pypi&logoColor=FFE873\">\n    </a>\n    <a href=\"https://github.com/psf/black\">\n        <img alt=\"code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\">\n    </a>\n    <a href=\"https://github.com/PyCQA/isort\">\n        <img alt=\"formatted with: isort\" src=\"https://img.shields.io/badge/formatted%20with-isort-blue.svg\">\n    </a>\n    <a href=\"https://mypy-lang.org/\">\n        <img alt=\"mypy: checked\" src=\"https://www.mypy-lang.org/static/mypy_badge.svg\">\n    </a>\n  </p>\n</div>\nBuild complex rules, operate them with Pydantic, and execute them in Python\n\n## Installation\n```shell\npip install pydantic-logic\n```\n\n## Examples\n\n### True expression\n```python\nfrom pydantic_logic import Logic, LogicExpression, Operator\n\ndata = {\n    \"Phone number\": \"123123123\",\n    \"some_value\": True,\n    \"some_other_value\": 1,\n}\n\nlogic = Logic(\n    expressions=[\n        LogicExpression.b(\"Phone number\", Operator.NE, \"adasdasdasd\"),\n        LogicExpression.b(\"some_value\", Operator.EQ, True),\n        LogicExpression.b(\"some_other_value\", Operator.GT, 0),\n    ]\n)\nassert logic.evaluate(data)\n```\n\n### False expression\n```python\nfrom pydantic_logic import Logic, LogicExpression, Operator\n\ndata = {\n    \"Phone number\": \"123123123\",\n    \"some_value\": True,\n    \"some_other_value\": 1,\n}\n\nlogic = Logic(\n    expressions=[\n        LogicExpression.b(\"Phone number\", Operator.EQ, \"123123123\"),\n        LogicExpression.b(\"some_value\", Operator.NE, False),\n        LogicExpression.b(\"some_other_value\", Operator.LT, 1),\n    ]\n)\nassert not logic.evaluate(data)\n```\n\n### Empty expression with default result\nSuitable if the expressions are set by the end users, not the code\n```python\nfrom pydantic_logic import Logic\n\ndata = {\n    \"Phone number\": \"123123123\",\n    \"some_value\": True,\n    \"some_other_value\": 1,\n}\n\nlogic = Logic(\n    expressions=[]\n)\nassert logic.evaluate(data, default_if_empty=True)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Description",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/barabum0/pydantic-logic",
        "Repository": "https://github.com/barabum0/pydantic-logic"
    },
    "split_keywords": [
        "python",
        " pydantic",
        " logic",
        " condition",
        " validation",
        " json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab65114ae634d5e70df96c98af3b996a3251f351a711c13a787f0eb9739d28f7",
                "md5": "072761baa4a29f4c4c2f32e2268be0a5",
                "sha256": "c2a1a000f24fe3f174d96b8757ed3a07d01c83b261d77ec17115136b54d7da37"
            },
            "downloads": -1,
            "filename": "pydantic_logic-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "072761baa4a29f4c4c2f32e2268be0a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 3943,
            "upload_time": "2024-11-26T14:57:32",
            "upload_time_iso_8601": "2024-11-26T14:57:32.567809Z",
            "url": "https://files.pythonhosted.org/packages/ab/65/114ae634d5e70df96c98af3b996a3251f351a711c13a787f0eb9739d28f7/pydantic_logic-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33d40f81712220122b28c086f6856ac784479838de3506d4987f943bb1279379",
                "md5": "dd86f50aef9ddff6db31d23994e36278",
                "sha256": "f3cdcc5d9a95916c6c9f628fa4d24765de6faf9d124b36c6e50c955f6f58b3cd"
            },
            "downloads": -1,
            "filename": "pydantic_logic-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "dd86f50aef9ddff6db31d23994e36278",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3138,
            "upload_time": "2024-11-26T14:57:34",
            "upload_time_iso_8601": "2024-11-26T14:57:34.235125Z",
            "url": "https://files.pythonhosted.org/packages/33/d4/0f81712220122b28c086f6856ac784479838de3506d4987f943bb1279379/pydantic_logic-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-26 14:57:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "barabum0",
    "github_project": "pydantic-logic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydantic-logic"
}
        
Elapsed time: 0.39047s