pypermissive


Namepypermissive JSON
Version 1.1.2 PyPI version JSON
download
home_pagehttps://github.com/kaliv0/pypermissive
SummaryValidation library
upload_time2024-12-06 22:53:24
maintainerNone
docs_urlNone
authorkaliv0
requires_python<4.0,>=3.12
licenseLICENSE
keywords validation library type validator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://github.com/kaliv0/pypermissive/blob/main/assets/permissive.jpg?raw=true" alt="Permissive Path">
</p>

---

# PyPermissive

[![tests](https://img.shields.io/github/actions/workflow/status/kaliv0/pypermissive/ci.yml)](https://github.com/kaliv0/pypermissive/actions/workflows/ci.yml)
![Python 3.x](https://img.shields.io/badge/python-3.12-blue?style=flat-square&logo=Python&logoColor=white)
[![PyPI](https://img.shields.io/pypi/v/pypermissive.svg)](https://pypi.org/project/pypermissive/)
[![Downloads](https://static.pepy.tech/badge/pypermissive)](https://pepy.tech/projects/pypermissive)
[![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](https://github.com/kaliv0/pypermissive/blob/main/LICENSE)

Validation library in Python, modeled after Pydantic

--------------------------------
## Example

Inherit from BaseModel and describe required types.<br>
<i>PyPermissive</i> supports validation for primitive types:
```python
class Employee(BaseModel):
    employee_id: int
    name: str
    salary: float
    elected_benefits: bool = False
    
employee = Employee(
    employee_id=1,
    name="Foo Bar",
    salary=123_000.00,
    elected_benefits=True,
)
```
collections:
```python
class Book(BaseModel):
    characters: dict[str, str]
    chapters: list[str]
    
book = Book(
    characters={"Pelleas": "he", "Melisande": "she"},
    chapters=["Beginning", "Middle", "End"]
)
```
unions, classes and fields.<br>

--------------------------------
Fields are similar to <i>pydantic</i> with one caveat: you need to give value type explicitly:
```python
class User(BaseModel):
    name: Field(type=str, default="Jimmie", frozen=True)
    age: Field(type=int, gt=18, lt=35)
    id: Field(type=UUID, default_factory=uuid4)
    email: Field(type=str, pattern=r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9-.]+$")
    nickname: Field(type=str, min_length=6, max_length=12)
    PIN: Field(type=str, field_validator=lambda x: x.isdigit())

```

--------------------------------
You can also use decorators:<br>
@ComputedField (invoke only from instances) and @ComputedClassField (invoke both on class and instance level)
```python
class Thesis:
    BAZZ = ["1", "2", "3"]

    def __init__(self):
        self.fizz = [1, 2, 3, 4, 5]
        self.buzz = [6, 7, 8, 9]

    @ComputedField
    def foo(self):
        return [val for val in itertools.product(self.fizz, self.buzz)]

    @ComputedClassField
    def bar(self):
        return list(itertools.permutations(self.BAZZ))

    
```

--------------------------------
The library supports @validate_call that checks both argument and return types:
```python
@validate_call
def some_func(delimiter: str, count: int, numbers: list[int]) -> str:
    return (delimiter * count).join([str(d) for d in numbers])
```

--------------------------------
@Interface checks on a class-definition level if the decorated class implements all described methods with the specified signature
```python
class MyInterface:
    def pow(self, x: int, y: int) -> int: ...


@Interface(MyInterface)
class Powerful:
    def pow(self, x: int, y: int) -> int:
        return x ** y
```

```python
class OtherInterface:
    def moo(self): ...


@Interface(MyInterface, OtherInterface)
class Frankenstein:
    def pow(self, x: int, y: int) -> int:
        return x ** y

    def moo(self):
        return "Yeah Mr. White..."
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kaliv0/pypermissive",
    "name": "pypermissive",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": "validation library, type validator",
    "author": "kaliv0",
    "author_email": "kaloyan.ivanov88@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/00/cb/30c4834e908e17c8003ea885e16618a2938a591cc7a686e7549e967fc5ae/pypermissive-1.1.2.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://github.com/kaliv0/pypermissive/blob/main/assets/permissive.jpg?raw=true\" alt=\"Permissive Path\">\n</p>\n\n---\n\n# PyPermissive\n\n[![tests](https://img.shields.io/github/actions/workflow/status/kaliv0/pypermissive/ci.yml)](https://github.com/kaliv0/pypermissive/actions/workflows/ci.yml)\n![Python 3.x](https://img.shields.io/badge/python-3.12-blue?style=flat-square&logo=Python&logoColor=white)\n[![PyPI](https://img.shields.io/pypi/v/pypermissive.svg)](https://pypi.org/project/pypermissive/)\n[![Downloads](https://static.pepy.tech/badge/pypermissive)](https://pepy.tech/projects/pypermissive)\n[![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](https://github.com/kaliv0/pypermissive/blob/main/LICENSE)\n\nValidation library in Python, modeled after Pydantic\n\n--------------------------------\n## Example\n\nInherit from BaseModel and describe required types.<br>\n<i>PyPermissive</i> supports validation for primitive types:\n```python\nclass Employee(BaseModel):\n    employee_id: int\n    name: str\n    salary: float\n    elected_benefits: bool = False\n    \nemployee = Employee(\n    employee_id=1,\n    name=\"Foo Bar\",\n    salary=123_000.00,\n    elected_benefits=True,\n)\n```\ncollections:\n```python\nclass Book(BaseModel):\n    characters: dict[str, str]\n    chapters: list[str]\n    \nbook = Book(\n    characters={\"Pelleas\": \"he\", \"Melisande\": \"she\"},\n    chapters=[\"Beginning\", \"Middle\", \"End\"]\n)\n```\nunions, classes and fields.<br>\n\n--------------------------------\nFields are similar to <i>pydantic</i> with one caveat: you need to give value type explicitly:\n```python\nclass User(BaseModel):\n    name: Field(type=str, default=\"Jimmie\", frozen=True)\n    age: Field(type=int, gt=18, lt=35)\n    id: Field(type=UUID, default_factory=uuid4)\n    email: Field(type=str, pattern=r\"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9-.]+$\")\n    nickname: Field(type=str, min_length=6, max_length=12)\n    PIN: Field(type=str, field_validator=lambda x: x.isdigit())\n\n```\n\n--------------------------------\nYou can also use decorators:<br>\n@ComputedField (invoke only from instances) and @ComputedClassField (invoke both on class and instance level)\n```python\nclass Thesis:\n    BAZZ = [\"1\", \"2\", \"3\"]\n\n    def __init__(self):\n        self.fizz = [1, 2, 3, 4, 5]\n        self.buzz = [6, 7, 8, 9]\n\n    @ComputedField\n    def foo(self):\n        return [val for val in itertools.product(self.fizz, self.buzz)]\n\n    @ComputedClassField\n    def bar(self):\n        return list(itertools.permutations(self.BAZZ))\n\n    \n```\n\n--------------------------------\nThe library supports @validate_call that checks both argument and return types:\n```python\n@validate_call\ndef some_func(delimiter: str, count: int, numbers: list[int]) -> str:\n    return (delimiter * count).join([str(d) for d in numbers])\n```\n\n--------------------------------\n@Interface checks on a class-definition level if the decorated class implements all described methods with the specified signature\n```python\nclass MyInterface:\n    def pow(self, x: int, y: int) -> int: ...\n\n\n@Interface(MyInterface)\nclass Powerful:\n    def pow(self, x: int, y: int) -> int:\n        return x ** y\n```\n\n```python\nclass OtherInterface:\n    def moo(self): ...\n\n\n@Interface(MyInterface, OtherInterface)\nclass Frankenstein:\n    def pow(self, x: int, y: int) -> int:\n        return x ** y\n\n    def moo(self):\n        return \"Yeah Mr. White...\"\n```\n",
    "bugtrack_url": null,
    "license": "LICENSE",
    "summary": "Validation library",
    "version": "1.1.2",
    "project_urls": {
        "Homepage": "https://github.com/kaliv0/pypermissive",
        "Repository": "https://github.com/kaliv0/pypermissive"
    },
    "split_keywords": [
        "validation library",
        " type validator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c5dd1547fc9d88f120b011ff15cb197859e17c73b28c14a97f6557fa5342b55",
                "md5": "fb699cffa6c5a79e44075b8df2a64465",
                "sha256": "aaf6561a0cdc786a8f3934fabcae3432d9a6bc7d04224995e601e2e0020be868"
            },
            "downloads": -1,
            "filename": "pypermissive-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fb699cffa6c5a79e44075b8df2a64465",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 6333,
            "upload_time": "2024-12-06T22:53:22",
            "upload_time_iso_8601": "2024-12-06T22:53:22.594905Z",
            "url": "https://files.pythonhosted.org/packages/9c/5d/d1547fc9d88f120b011ff15cb197859e17c73b28c14a97f6557fa5342b55/pypermissive-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00cb30c4834e908e17c8003ea885e16618a2938a591cc7a686e7549e967fc5ae",
                "md5": "d6498e0c625bf1d4c54d9c7dde51edf1",
                "sha256": "7a087a25f9546e66d03ef15eed02858a6e1328b522374e2a5d5d11cbb08f04f6"
            },
            "downloads": -1,
            "filename": "pypermissive-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d6498e0c625bf1d4c54d9c7dde51edf1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 5204,
            "upload_time": "2024-12-06T22:53:24",
            "upload_time_iso_8601": "2024-12-06T22:53:24.354620Z",
            "url": "https://files.pythonhosted.org/packages/00/cb/30c4834e908e17c8003ea885e16618a2938a591cc7a686e7549e967fc5ae/pypermissive-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 22:53:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kaliv0",
    "github_project": "pypermissive",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pypermissive"
}
        
Elapsed time: 1.30777s