A lightweight Python validation library for checking data before using it.
Project description
PyValidX
PyValidX is a small Python validation library that helps developers check data before using it.
It is useful for form input, API request bodies, configuration files, and any place where incoming data should follow clear rules.
Installation
pip install pyvalidx
Quick Start
from pyvalidx import validate
validate("john@example.com", ["required", "email"])
validate("secure-password", ["required", "min:8"])
validate(25, ["required", "between:18,100"])
If the value is invalid, PyValidX raises a ValidationError.
from pyvalidx import ValidationError, validate
try:
validate("", ["required"])
except ValidationError as error:
print(error)
Available Rules
| Rule | Example | Meaning |
|---|---|---|
required |
required |
Value cannot be empty |
email |
email |
Value must look like an email address |
min |
min:8 |
Value length or number must be at least 8 |
max |
max:100 |
Value length or number must be at most 100 |
between |
between:18,100 |
Number must be between 18 and 100 |
regex |
regex:^[A-Z]+$ |
Value must match a regular expression |
in |
in:admin,user |
Value must be one of the allowed options |
Validate Dictionaries
from pyvalidx import validate_data
rules = {
"name": ["required", "min:2"],
"email": ["required", "email"],
"age": ["required", "between:18,100"],
}
validate_data(
{"name": "Jane", "email": "jane@example.com", "age": 30},
rules,
)
Custom Validators
from pyvalidx import validate
def starts_with_a(value):
return str(value).startswith("A")
validate("Alice", [starts_with_a])
Custom validators can return:
Truefor validFalsefor invalid- A string error message for invalid
Development
python -m pip install -e . pytest build twine
python -m pytest
python -m build
python -m twine check dist/*
Publish to PyPI
First test with TestPyPI:
python -m twine upload --repository testpypi dist/*
Then upload to PyPI:
python -m twine upload dist/*
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
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 pyvalidyr-0.1.0.tar.gz.
File metadata
- Download URL: pyvalidyr-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8edf23db1decfb9ef8a196d3ccf9ac0aaf96e48d0a2f031df7f001f8c3c4e1d
|
|
| MD5 |
ff71ca026021d7ab484113125464d60c
|
|
| BLAKE2b-256 |
b55e1553aa42b7e756aa211680a19960c6e51806a99616f1f959748baad9fb8c
|
File details
Details for the file pyvalidyr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyvalidyr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5fe42440512f9bcd6d1a0b9b71917cf9ef507f369aa92be8f4d1f1782a0eae3
|
|
| MD5 |
8c99c893824eeb98ca6f4555cc5e677d
|
|
| BLAKE2b-256 |
7cc291cabf8581b0232f8724e4bdca9503eb52331e36d99aad191d5a84fefb7a
|