概要
このライブラリは、値の正常性を検証するバリデータ群と、検証前に型変換を試みるコンバータ群を提供するユーティリティです。
ディスクリプタとしてクラス属性に使用することで不適切な値の代入を防止できるほか、単独の関数・オブジェクトとして値を検証・変換することも可能です。
インストール
インストール
pip install otsuvalidator
アップデート
pip install -U otsuvalidator
アンインストール
pip uninstall otsuvalidator
モジュール
本ライブラリは主に以下の3つのモジュールで構成されています。
| モジュール名 | 概要 |
|---|---|
bases |
バリデータ・コンバータの基底クラスを定義。自作のバリデータを作成する際に使用します。 |
validators |
値の検証のみを行うバリデータ群が定義されています。 |
converters |
型変換を試みた上で検証を行うコンバータ群が定義されています。 |
basesモジュールのクラス
Validator: すべてのバリデータおよびコンバータの基底クラス。VContainer: コンテナ(リストや辞書など)用バリデータの基底クラス。要素が可変なオブジェクトを検証する際に使用します。Converter: コンバータの基底クラス。VChain: バリデータ・コンバータの連結をサポートします。
validatorsモジュールのクラス
※破線されたクラスは非推奨です。
| クラス | 概要 | 期待する型 |
|---|---|---|
| VBool | 真偽値オブジェクトか検証 | bool |
| VChoice | 規定の選択肢の中から1つが選択されているか検証 | Any |
| VNumerical / |
適切な数値か検証 | int / float |
| VFloat | 適切な浮動小数点数か検証 | float |
| VInt | 適切な整数か検証 | int |
| VPath | 適切なパスか検証 | pathlib.Path |
| VString | 適切な文字列か検証 | str |
適切な正規表現か検証。VString(pattern=...)に合併。 |
str | |
| VDict | 適切な構造の辞書か検証 | dict |
| VList | 適切なリストか検証 | list |
| VTuple | 適切なタプルか検証 | tuple |
| VTimedelta | 適切なtimedelta型か検証 | datetime.timedelta |
convertersモジュールのクラス
※破線されたクラスは非推奨です。
| クラス | 概要 |
|---|---|
| CBool | Yes / Noとして解釈できる値に対しbool型への変換を試みて検証 |
| CNumerical / |
int / float型への自動変換を試みて検証 |
| CFloat | float型への自動変換を試みて検証 |
| CInt | int型への自動変換を試みて検証 |
| CPath | pathlib.Path型への自動変換を試みて検証 |
| CString | str型への返還を試みて検証 |
| CTimedelta | datetime.timedelta型への自動変換を試みて検証 |
継承規則
自作のバリデータやコンバータを正しく定義するための規則です。
Validator継承規則
- 命名: クラス名は
V{検証したいクラス名}とします(例:VString)。 - 継承:
Validatorクラスを継承します。 - 定義:
validateメソッドを定義し、検証が成功した場合は受け取ったvalueを返します。 - 変換:
validate内でvalueの型変換を行ってはいけません(変換を行う場合はConverterを使用)。
VContainer継承規則
- 命名: クラス名は
V{検証したいクラス名}とします(例:VList)。 - 継承:
VContainerクラスを継承します。 - 定義:
validateメソッドを定義し、検証通過時はvalueを返します。中身の各要素への検証規則を設定します。 - 変換: コンテナ自体の型変換は行いません。ただし要素に対してはオプション設定に応じます。
Converter継承規則
- 命名:
C{変換検証したいクラス名}とします(例:CInt)。 - 継承:
(対象クラスのバリデータ, Converter)の順で多重継承します。 - 定義:
validate内で型変換を行い、return super().validate(value)で検証して返します。
Metadata
Release files for otsuvalidator 1.1.2.312
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| otsuvalidator-1.1.2.312.tar.gz | 14.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| otsuvalidator-1.1.2.312-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.6 kB
Release files / otsuvalidator-1.1.2.312.tar.gz
| Download URL | otsuvalidator-1.1.2.312.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe398513e95b02d4305f0c5ee8f2170c328f3b97f36ced98cd62f3ad5b94a52d
|
|
BLAKE2b-256 checksum How to use checksums |
a8b364626e472a9f7418ac4cfce5dc22823dc35a118cafe31f0214d893b5a344
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / otsuvalidator-1.1.2.312-py3-none-any.whl
| Download URL | otsuvalidator-1.1.2.312-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aebbd2add628792ff1c240b91da0a8dcb8388641578026c5eb2dbd2cf72b4f7b
|
|
BLAKE2b-256 checksum How to use checksums |
f52ae3818d40b488788f870d9c144619d39d6b34f4ec53616315a790fac061d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for otsuvalidator 1.1.2.312
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.