pypermissive


Namepypermissive JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryValidation library
upload_time2024-08-14 15:54:09
maintainerNone
docs_urlNone
authorkaliv0
requires_python<4.0,>=3.12
licenseLICENSE
keywords
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/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/)
[![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>
<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])
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pypermissive",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": null,
    "author": "kaliv0",
    "author_email": "kaloyan.ivanov88@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/99/72/5720ecfadab393b1c5ad96de484cd6d708c3c18fc68c90e7471505b795d5/pypermissive-1.0.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://github.com/kaliv0/pypermissive/blob/main/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[![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## 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```\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```\n\nunions, classes and fields.<br>\n<br>Fields are similar to <i>pydantic</i> with one caveat: you need to give value type explicitly:\n\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\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\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",
    "bugtrack_url": null,
    "license": "LICENSE",
    "summary": "Validation library",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "756a344a98e05302e0556ed15247b9db2a9932c01a4ccf5b98439ab163416207",
                "md5": "d45efd30a835f92501d19acfd22cfb7a",
                "sha256": "785f894b3981307b807327b3aa145943bd28d8eebf8146e687b88316e33fb688"
            },
            "downloads": -1,
            "filename": "pypermissive-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d45efd30a835f92501d19acfd22cfb7a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 5680,
            "upload_time": "2024-08-14T15:54:08",
            "upload_time_iso_8601": "2024-08-14T15:54:08.220811Z",
            "url": "https://files.pythonhosted.org/packages/75/6a/344a98e05302e0556ed15247b9db2a9932c01a4ccf5b98439ab163416207/pypermissive-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "99725720ecfadab393b1c5ad96de484cd6d708c3c18fc68c90e7471505b795d5",
                "md5": "d1bb43554e64ddd1c5fa7610bfcd828d",
                "sha256": "8cd5a6ac43d70454ad3ef5769c80506cd6ff990b90a0c21df7ee20850b38e02e"
            },
            "downloads": -1,
            "filename": "pypermissive-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d1bb43554e64ddd1c5fa7610bfcd828d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 4595,
            "upload_time": "2024-08-14T15:54:09",
            "upload_time_iso_8601": "2024-08-14T15:54:09.652536Z",
            "url": "https://files.pythonhosted.org/packages/99/72/5720ecfadab393b1c5ad96de484cd6d708c3c18fc68c90e7471505b795d5/pypermissive-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-14 15:54:09",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pypermissive"
}
        
Elapsed time: 0.44050s