A composable, expressive data validation library for python
Project description
valify
A composable, expressive data validation library for Python.
Installation
pip install valify
Quick Start
from valify import Schema, StringValidator, IntValidator, EmailValidator
schema = Schema({
"name": StringValidator(min_length=2, max_length=50),
"age": IntValidator(min_value=0, max_value=120),
"email": EmailValidator(),
})
# Valid data — returns cleaned, validated dictionary
result = schema.validate({
"name": "Alice",
"age": 30,
"email": "alice@example.com",
})
print(result)
# {'name': 'Alice', 'age': 30, 'email': 'alice@example.com'}
# Invalid data — raises ValidationError with ALL errors at once
schema.validate({
"name": "A",
"age": -5,
"email": "not-an-email",
})
# ValidationError: Validation failed:
# name: Must be at least 2 characters long.
# age: Must be at least 0.
# email: 'not-an-email' is not a valid email address.
Validators
| Validator | What it checks |
|---|---|
StringValidator |
Strings, with optional min/max length |
IntValidator |
Integers, with optional min/max value |
FloatValidator |
Floats, with optional min/max value |
BoolValidator |
Booleans, with optional string coercion |
EmailValidator |
Email address format |
Validators in Detail
StringValidator
from valify import StringValidator
v = StringValidator(
min_length=2, # minimum character length
max_length=50, # maximum character length
strip=True, # strip whitespace before validating (default: True)
)
IntValidator
from valify import IntValidator
v = IntValidator(
min_value=0, # minimum allowed value
max_value=120, # maximum allowed value
coerce=False, # if True, converts "42" -> 42 (default: False)
)
EmailValidator
from valify import EmailValidator
v = EmailValidator()
v.validate("alice@example.com") # returns "alice@example.com"
Using Validators Standalone
Validators work without a Schema too:
from valify import IntValidator
from valify.exceptions import ValidationError
v = IntValidator(min_value=0)
try:
v.validate(-1)
except ValidationError as e:
print(e.message) # Must be at least 0.
print(e.value) # -1
Error Handling
from valify.exceptions import (
ValifyError, # base — catches everything
ValidationError, # a value failed validation
RequiredFieldError, # a required field was missing
SchemaError, # the schema definition is invalid
)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
valify-0.2.0.tar.gz
(8.7 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 valify-0.2.0.tar.gz.
File metadata
- Download URL: valify-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86801b8f86be6e5cfff19a5d66e392665e17317862622882acb053607806ab6e
|
|
| MD5 |
109f8c7ba36572acee8add1997f7a3cd
|
|
| BLAKE2b-256 |
874f28c8589a2672bc1441cc5392f3f833fac2f4392109165ce2c428509f60c2
|
File details
Details for the file valify-0.2.0-py3-none-any.whl.
File metadata
- Download URL: valify-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
641d36905fd3f8ade4c5d1f4a2af2ada67f4b3eb3a71eef08e97fd132cab5c7c
|
|
| MD5 |
e7048ab57ba1315e77bbb160b8fa61a7
|
|
| BLAKE2b-256 |
89c558348ac6b1535a3c42c84184093ffde6666058cadd31422e2e054c0957ef
|