Skip to main content

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

Metadata

Release files for larzvalidate 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for larzvalidate 0.1.0
File Size Uploaded
larzvalidate-0.1.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for larzvalidate 0.1.0
File Interpreter ABI Platform
larzvalidate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / larzvalidate-0.1.0.tar.gz

Download URL larzvalidate-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
456a5b73dba77935b28ef8e20773a6df6f2d5782253a5b79c5576957b876485d
BLAKE2b-256 checksum
How to use checksums
9b1d582b79c13bd7e8764c48c1d1ff03a4dc15b566b9817957e319904b04aeb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / larzvalidate-0.1.0-py3-none-any.whl

Download URL larzvalidate-0.1.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18dc1a60a22754d1172a8f6f488e2e5e549bb30779f9b1bd846d8cb81273727d
BLAKE2b-256 checksum
How to use checksums
a181a2dfa1e6070f1ba3c3d4e3745f49c4aaadfb4173923178d57b22e4ad6b49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page