PyPermissive
Validation library in Python, modeled after Pydantic
Example
Inherit from BaseModel and describe required types.
PyPermissive supports validation for primitive types:
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:
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.
Fields are similar to pydantic with one caveat: you need to give value type explicitly:
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:
@ComputedField (invoke only from instances) and @ComputedClassField (invoke both on class and instance level)
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:
@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
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
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..."
Metadata
Release files for pypermissive 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypermissive-1.1.3.tar.gz | 5.0 kB | Without provenance | Details for pypermissive-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypermissive-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for pypermissive-1.1.3-py3-none-any.whl |
Total release size: 11.3 kB
Release files / pypermissive-1.1.3.tar.gz
| Download URL | pypermissive-1.1.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aade024dc48034d514e0ac2af2b905f5c36df96b53a4cdfeaa77af26b665917e
|
|
BLAKE2b-256 checksum How to use checksums |
9d1271e3d5c146c7d6185e3cc04dae342c1fccb3ee1beee9ea02a3f81ef5b3bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.0 CPython/3.12.7 Linux/6.11.0-24-generic
|
Release files / pypermissive-1.1.3-py3-none-any.whl
| Download URL | pypermissive-1.1.3-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2ca65a88f7c8e8edf5b8bf379d7a1838ec1ea938cb10140b2e64e51e8f83be4
|
|
BLAKE2b-256 checksum How to use checksums |
8a06a6c7010a1fd296d0e1d2d15aa5e5dbc9496b3b8463bb0262f38921ae36c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.0 CPython/3.12.7 Linux/6.11.0-24-generic
|
Security for pypermissive 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.