Library for creating a custom validator
Reason this release was yanked:
# Project Relocation. **The project has been successfully moved to a new name and address**. Now you can find it at the following link: https://github.com/m62624/flexible_inspect
Project description
PYSTVAL
The Library
Pystval is a powerful Rust library for text validation and analysis. It allows you to create custom errors with modifiers and define sub-corrections for each rule. With Pystval, you can build versatile validators that handle any text and enforce specific requirements. Customize error behavior and apply sub-corrections based on specific cases or conditions. Pystval empowers you to create accurate and adaptable validators for various text processing needs.
The difference between this library and normal use of regular expressions is that you can combine different rules with modifiers, and the results of these rules are automatically passed to subexpressions, etc.
Quick Look
Click me
from pystval import Rule, MatchRequirement, TemplateValidator, PystvalException
# Creating a validator cartridge
class ErrorInvalidFormat(PystvalException):
message = ":: Invalid Format ::"
rules = [
# root rule
Rule(r"(?i)abc.+\d+", MatchRequirement.MustBeFound).extend([
# 1-subrule of root rule
Rule(r"\d{3}-\d{4}-\d{2}", MatchRequirement.MustBeFound).extend([
# 1-subrule of 1-subrule
Rule(r"^\d{3}", MatchRequirement.MustBeFound).extend(
# 1-subrule of 1-subrule of 1-subrule
[Rule(r"[0-1][1-2][1-3]", MatchRequirement.MustBeFound)]),
# 2-subrule of 1-subrule
Rule(r"-", MatchRequirement.MustBeFound),
]),
])
]
# Creating a validator cartridge
# We get this class as an error because `MustNotBeFound` is specified, but we find in the text, at the very end of `12345`
class ErrorNumber(PystvalException):
message = "Custom error with value : {num}"
rules = [
Rule(r"(?<num>\d+(?!\d|-|\s))", MatchRequirement.MustNotBeFound)
]
text = b"This is a complex text with aBc_122-4567-99 and def. The number is 12345"
# In the validator we load the cartridges, which will be used to check the data
validator = TemplateValidator([ErrorInvalidFormat, ErrorNumber])
# We get a list of errors based on those classes whose rules failed
list_error = validator.validate(text)
# errors
if list_error is not None:
for error in list_error:
try:
raise error
except PystvalException as e:
# show a specific message based on the class
print(e.report)
OUTPUT: Custom error with value : 12345
Installation
PyPi.
Installation from PyPi
pip install pystval
Github packages
Under Releases
choose your platform.
Unpack the archive and install
pip install pystval-version-platform.whl
Documentation
Documentation of use: docs
License
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 Distributions
Built Distributions
Hashes for pystval-1.1.0-cp37-abi3-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc577d9c2afc406354e90b5177fa8474d68b7c1bf537869a7747f46a91d18adc |
|
MD5 | 814135d60bde4a38c2315c51e4df4f1a |
|
BLAKE2b-256 | d0098b88acbd4b8b15603b932bf0b2f9ec3b543ae936da5bfa9fc73491f590d7 |
Hashes for pystval-1.1.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 884b000cb35e6f3e1619ef378fa85354fb72d297b9d34169123a9060ee33d63e |
|
MD5 | 036474e05661ee32a0eaa987ca51aae4 |
|
BLAKE2b-256 | 9b48f8be261a669e2664058a88948352e4f87a620cb8dfb0c6f5cb28a5fdec1b |
Hashes for pystval-1.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375b22d206951accb26aaf13c398ac9759447e7729059d3ab987a1c1d6f6f1f4 |
|
MD5 | d842f154dc798d767dc024e3752ba6cd |
|
BLAKE2b-256 | 7dfea873b965818d79c8e7e093ccad778461b6a722a1cd5fff50e8a08c76b40f |
Hashes for pystval-1.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6308988d99d91db27b8a124df13a0ef88af6f08a0427a21e9ca95854ce34ee63 |
|
MD5 | 8d86e8e335c41dff37bd5f9becf0e915 |
|
BLAKE2b-256 | 6ba8cbb5fbe4de65f8e796f4741cc047009659056e343b1669fd52f02a02c97a |
Hashes for pystval-1.1.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82dc1ed28a27557fe5426b060c9de26adc94a6d32b39dd09a950c4a6d221f489 |
|
MD5 | 96051cba4524d1699d890be091d2069d |
|
BLAKE2b-256 | 56200b1f8d72b18f2ba01249e6ba3f7ccfdf9b5eb185b8d99e6b2437acc099d1 |
Hashes for pystval-1.1.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2401238b0abe99620e24720b52bcd89aee5aa4eba9348b9ef52c11c7680eb0aa |
|
MD5 | 8029ce96638d6346bdb70b3d0d3673a6 |
|
BLAKE2b-256 | 6b97ecd9d1d6ee25ae3ae5e1843188367841e1a60f050cbfae42a4823b8d4b39 |