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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzvalidate-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzvalidate-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for larzvalidate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 456a5b73dba77935b28ef8e20773a6df6f2d5782253a5b79c5576957b876485d
MD5 e31ff1677278eea7dafdcf35ea0cef60
BLAKE2b-256 9b1d582b79c13bd7e8764c48c1d1ff03a4dc15b566b9817957e319904b04aeb0

See more details on using hashes here.

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

Hashes for larzvalidate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18dc1a60a22754d1172a8f6f488e2e5e549bb30779f9b1bd846d8cb81273727d
MD5 a6f4357fc95694bbbc81975aebb28a19
BLAKE2b-256 a181a2dfa1e6070f1ba3c3d4e3745f49c4aaadfb4173923178d57b22e4ad6b49

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page