Skip to main content
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Description: vlde: easy-to-use for validate data
=========
.. image:: https://img.shields.io/pypi/v/vlde.svg
:target: https://pypi.org/project/vlde/

.. image:: https://img.shields.io/pypi/l/vlde.svg
:target: https://pypi.org/project/vlde/

.. image:: https://travis-ci.org/xiaojieluo/vlde.svg?branch=master
:target: https://travis-ci.org/xiaojieluo/vlde

.. image:: https://codecov.io/gh/xiaojieluo/vlde/branch/master/graph/badge.svg
:target: https://codecov.io/gh/xiaojieluo/vlde

使用
-----

.. code-block:: python

from vlde import Validator

v = Validator(return_format='object')
result = v.set_rules('hello', 'required|dict|max_length:3')
if result.status is False:
print('\n'.join(result.error))

或者捕获异常:

.. code-block:: python

from vlde import ValidateError, Validator

v = Validator(return_format='exception')
try:
v.set_rules('hello', 'required|dict')
except ValidateError as e:
print(e)

开启规则错误提示
--------------
默认情况下,若传入错误的规则名称, vlde 会找不到验证规则,并返回验证通过。如果想关闭此功能,只需要在定义变量时,传入 `warning_rule = True` 即可

.. code-block:: python

from vlde import ValidateError, Validator, RulesError

v = Validator(warning_rule=True)
try:
v.set_rules('hello' 'strssss')
except RulesError as e:
print(e)

也可以为单个的 set_rules 单独设置 warning_rule:

.. code-block:: python

from vlde import ValidateError, Validator

v = Validator()
v.set_rules('hello', 'strssss', warning_rule=False)
try:
v.set_rules('hello', 'strssss', warning_rule=True)
except RulesError as e:
print(e)


validate 内置规则
------------------------

规则参考
^^^^^^^^^^^^^

下表列出了 vlde 可用的规则

+--------------+------+----------------------------------------+---------------------------------------------------+
| 规则 | 参数 | 描述 | 例子 |
+==============+======+========================================+===================================================+
| required | | 如果变量值为空或者为 None, 验证不通过 | `v.set_rules(None, 'required')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| min_length | int | 如果变量值长度小于参数值, 验证不通过 | `v.set_rules('hello','min_length:6')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| max_length | int | 如果变量值长度大于参数值, 验证不通过 | `v.set_rules('hello', 'max_length:2')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| exact_length | int | 如果变量值长度不等于参数值, 验证不通过 | `v.set_rules('hello', 'exact_length:5')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| in_list | list | 如果变量值不在规定的列表中,验证不通过 | `v.set_rules('hello', 'in_list[hello, helloss]')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| str | | 如果变量类型不为 str, 验证不通过 | `v.set_rules('hello', 'str')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| dict | | 如果变量类型不为 dict, 验证不通过 | `v.set_rules({'name':'luo'}, 'dict')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| list | | 如果变量类型不为 list, 验证不通过 | `v.set_rules([1, 2, 3], 'list')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| bool | | 如果变量类型不为 bool, 验证不通过 | `v.set_rules(True, 'bool')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| float | | 如果变量类型不为 foat, 验证不通过 | `v.set_rules(1.1,'float')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| int,integer | | 如果变量类型不为 int, 验证不通过 | `v.set_rules(10, 'int')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| tuple, tup | | 如果变量类型不为 tuple, 验证不通过 | `v.set_rules((1, 2, 3), 'tuple')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| ipv4 | str | 如果变量值不为 ipv4 地址, 验证不通过 | `v.set_rules('192.168.1.1', 'ipv4')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| ipv6 | str | 如果变量值不为 ipv6 地址, 验证不通过 | `v.set_rules('5e:0:0:0:0:0:5668:eeee', 'ipv6')` |
+--------------+------+----------------------------------------+---------------------------------------------------+
| email | str | 如果变量值不为邮箱地址, 验证不通过 | `v.set_rules('xiaojieluoff@gmail.com' 'email')` |
+--------------+------+----------------------------------------+---------------------------------------------------+

规则容错
^^^^^^
* `int , integer` 都指代 int 类型
* `tuple, tup` 都指代 tuple 类型

Keywords: simple data validate library
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3

Release files for vlde 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vlde 0.3.0
File Size Uploaded
vlde-0.3.0.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vlde 0.3.0
File Interpreter ABI Platform
vlde-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / vlde-0.3.0.tar.gz

Download URL vlde-0.3.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e5def80ff63028da6742959096d056c240f835bf344bb57f940ffd00117e49f2
BLAKE2b-256 checksum
How to use checksums
f1970a4d4a2085d1accd066ec580b5bb9822c1fb349bd1edf7b63b5a0c31acda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / vlde-0.3.0-py3-none-any.whl

Download URL vlde-0.3.0-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
924e7143b090b8a1dbdbc84cebc1b0a4ed6f36373b7fbe40cd2076f0f9e767d1
BLAKE2b-256 checksum
How to use checksums
396cc02d2f9645289d0fc5fd85684bdd8ac240b22386acf3fa2d0aff3f1d4c29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page