larzvalidate
Validate input data against a schema — the guard every real app needs.
Data from forms, APIs and files is untrustworthy: fields go missing, numbers arrive as text, strings are too long. larzvalidate lets you declare what valid data looks like — a small schema of fields with rules — and checks input against it, returning clean, type-coerced data or clear per-field error messages. Zero dependencies.
Install
pip install larzvalidate
Use
from larzvalidate import validate, Field, ValidationError, EMAIL
schema = {
"name": Field(str, required=True, min=1, max=50),
"age": Field(int, min=0, max=150),
"email": Field(str, required=True, pattern=EMAIL),
"role": Field(str, choices=["user", "admin"], default="user"),
}
clean = validate({"name": "Ada", "age": "36", "email": "a@b.co"}, schema)
# {'name': 'Ada', 'age': 36, 'email': 'a@b.co', 'role': 'user'}
Learn to code with Larz
Part of the learn-to-code toolkit in the Larz stack — see the Learn to Code platform. The gatekeeper for real forms and APIs.
Tests
python -m unittest discover -s tests -v # 7 tests
License
MIT (c) larz-scripter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 larzvalidate-0.1.0.tar.gz.
File metadata
- Download URL: larzvalidate-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
456a5b73dba77935b28ef8e20773a6df6f2d5782253a5b79c5576957b876485d
|
|
| MD5 |
e31ff1677278eea7dafdcf35ea0cef60
|
|
| BLAKE2b-256 |
9b1d582b79c13bd7e8764c48c1d1ff03a4dc15b566b9817957e319904b04aeb0
|
File details
Details for the file larzvalidate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzvalidate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18dc1a60a22754d1172a8f6f488e2e5e549bb30779f9b1bd846d8cb81273727d
|
|
| MD5 |
a6f4357fc95694bbbc81975aebb28a19
|
|
| BLAKE2b-256 |
a181a2dfa1e6070f1ba3c3d4e3745f49c4aaadfb4173923178d57b22e4ad6b49
|