Lightweight validation for python objects.
Project description
strictobject
Lightweight validation for python objects.
Examples:
- Simple validation
from strictobject import StrictObject class A(StrictObject): num: int A(num=0) # ok A(num=42) # ok A(num="not an int") # will throw a TypeError
- Custom validation
from strictobject import StrictObject class B(StrictObject): fortytwo: Union[int|str] # custom validators must by named by "validate_" followed by # the class attribute name, and they should return a bool def validate_fortytwo(self, val) -> bool: return int(val) == 42 B(num=42) # ok B(num="42") # ok B(num=123) # will throw a TypeError
Works with all built-in types, and with special types List, Union, Optional from package typing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
strictobject-0.0.1.tar.gz
(11.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strictobject-0.0.1.tar.gz.
File metadata
- Download URL: strictobject-0.0.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a02b1f324f6781368bc40c690203b7650b0a9e02acdf20465087bc74e10f239
|
|
| MD5 |
8c1be04706da8fe3c90635ad72ce258e
|
|
| BLAKE2b-256 |
ea6715eab94392ae1431ded05aa2f92752c2912225d3440a01028ac6f08dd555
|
File details
Details for the file strictobject-0.0.1-py3-none-any.whl.
File metadata
- Download URL: strictobject-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
714701bd95af453e539b1711fd11d123dc6da2d777d0499b7a1170a93a58f606
|
|
| MD5 |
313b1a2fb6b7f0b3c4b5143ec6295953
|
|
| BLAKE2b-256 |
3e223cb215c3dcf1250f918bdc8687597ceab085a35ba93e45a9ce5af94a7372
|