XenValidator is schema validation library for Python, You can Validate Strings, Numbers, Objects, Arrays, Dates, URLs, Ip addresses & more. You can even create your custom validators! Make sure to give it a ⭐ on github.
Project description
XenValidator
XenValidator is a powerful, flexible, and easy-to-use Python library for validating data structures. It simplifies the process of defining complex validation rules, handling cross-field dependencies, and providing informative error messages.
Features
Comprehensive Validation: Supports validation for strings, numbers, dates, arrays, urls, and custom data types.
Custom Error Handling: Easily customize error messages for various validation rules.
Flexible Date Formats: Supports multiple date formats to match various use cases.
Installation
Install XenValidator using pip:
pip install xenvalidator
Example usage:
Import the package into to your app:
from XenValidator import X, Object, ValidationError
Create and validate the schema.
Schema = Object({
"Name": X["STRING"](),
"Age": X["NUMBER"]().min(2),
"Tags": X["ARRAY"](),
"IsProMember": X["BOOLEAN"](),
"Auth": Object({
"Email": X["STRING"]().email().required(),
"Password": X["Password"]().min(8).max(64).required().message("Password is required and must be 8 characters long."),
"IpAddress": X["IPADDRESS"]().required().message("Invalid IP address."),
"JoinedOn": X["DATE"](),
}),
"SiteName": X["URL"](),
})
try:
Data = {
"Name": "John Doe",
"Age": 18,
"Tags": ["Live streamer", "Web designer", "Front-end developer"],
"IsProMember": False,
"Auth": {
"Email": "mail@example.com",
"Password": "SecurePassword123&",
"IpAddress": "127.0.0.1",
"JoinedOn": "2024-11-05",
},
"SiteName": "https://mysite.com",
}
Schema.validate(Data)
print("Data is valid:", Data)
except ValidationError as e:
print("Data is invalid:", e)
Explanation
- Name: Required field validated as a string.
- Age: Number field with a minimum value of 2.
- Tags: Array field validated to ensure it is indeed an array.
- IsProMember: Boolean field indicating if the user is a pro member.
- Auth: Nested object for authentication details.
- Email: Required field validated as a valid email.
- Password: Required string with length between 8 and 64 characters.
- IpAddress: Required field validated as a valid IP address.
- JoinedOn: Optional date field.
- SiteName: Optional field validated as a URL.
- Country: Required string field for the user's country.
- Phone: Optional string field for the phone number.
- Interests: Array of strings representing user interests.
- Balance: Number field with a minimum value of 0.
- LastLogin: Optional date field indicating the last login date.
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 XenValidator-0.1.5.tar.gz.
File metadata
- Download URL: XenValidator-0.1.5.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b42f32be4192cb8396d4e667a6562344cf7817aa88b474e08475c66442f8c6fa
|
|
| MD5 |
2a92ca9925e533b660e353ed287173f1
|
|
| BLAKE2b-256 |
b1d76f7ce956e3d1d3bd89b99c58311f70d215afd3b7fb7f7ab23aba716a6688
|
File details
Details for the file XenValidator-0.1.5-py3-none-any.whl.
File metadata
- Download URL: XenValidator-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
150fc3f2c22858124752b30ad81cc4444c2602a3b7207cc144411e7b96cc5236
|
|
| MD5 |
7d0810064d2a86ade1bbe6457e44553f
|
|
| BLAKE2b-256 |
6b19cee634ff0e98ceb1d4ce976fab718edff90f45e22b6816ac81a2b36dd68c
|