Skip to main content

概要

このライブラリは、値の正常性を検証するバリデータ群と、検証前に型変換を試みるコンバータ群を提供するユーティリティです。
ディスクリプタとしてクラス属性に使用することで不適切な値の代入を防止できるほか、単独の関数・オブジェクトとして値を検証・変換することも可能です。


インストール

インストール

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 / VNumber 適切な数値か検証 int / float
VFloat 適切な浮動小数点数か検証 float
VInt 適切な整数か検証 int
VPath 適切なパスか検証 pathlib.Path
VString 適切な文字列か検証 str
VRegex 適切な正規表現か検証。VString(pattern=...)に合併。 str
VDict 適切な構造の辞書か検証 dict
VList 適切なリストか検証 list
VTuple 適切なタプルか検証 tuple
VTimedelta 適切なtimedelta型か検証 datetime.timedelta

convertersモジュールのクラス

※破線されたクラスは非推奨です。

クラス 概要
CBool Yes / Noとして解釈できる値に対しbool型への変換を試みて検証
CNumerical / CNumber int / float型への自動変換を試みて検証
CFloat float型への自動変換を試みて検証
CInt int型への自動変換を試みて検証
CPath pathlib.Path型への自動変換を試みて検証
CString str型への返還を試みて検証
CTimedelta datetime.timedelta型への自動変換を試みて検証

継承規則

自作のバリデータやコンバータを正しく定義するための規則です。

Validator継承規則

  1. 命名: クラス名はV{検証したいクラス名}とします(例: VString)。
  2. 継承: Validatorクラスを継承します。
  3. 定義: validateメソッドを定義し、検証が成功した場合は受け取ったvalueを返します。
  4. 変換: validate内でvalueの型変換を行ってはいけません(変換を行う場合はConverterを使用)。

VContainer継承規則

  1. 命名: クラス名はV{検証したいクラス名}とします(例: VList)。
  2. 継承: VContainerクラスを継承します。
  3. 定義: validateメソッドを定義し、検証通過時はvalueを返します。中身の各要素への検証規則を設定します。
  4. 変換: コンテナ自体の型変換は行いません。ただし要素に対してはオプション設定に応じます。

Converter継承規則

  1. 命名: C{変換検証したいクラス名}とします(例: CInt)。
  2. 継承: (対象クラスのバリデータ, Converter)の順で多重継承します。
  3. 定義: validate内で型変換を行い、return super().validate(value)で検証して返します。

Metadata

Release files for otsuvalidator 2.0.2

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

Source distribution (sdist)

Source distribution for otsuvalidator 2.0.2
File Size Uploaded Provenance
otsuvalidator-2.0.2.tar.gz 14.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 27.9 kB

Release files / otsuvalidator-2.0.2.tar.gz

Download URL otsuvalidator-2.0.2.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
01ea65f50df5e09e376d493cdc123218f65b3aa0a5c12a3843f3fb5a9b5e2539
BLAKE2b-256 checksum
How to use checksums
62b8c322f5e2c6812102a65adafbc8dd73608e3bfa789ebe980b2c8dcdecd897
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / otsuvalidator-2.0.2-py3-none-any.whl

Download URL otsuvalidator-2.0.2-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bed41974dad7a13de628e5812bca54f4e9be0d194740e908acdacf8e0b319e0d
BLAKE2b-256 checksum
How to use checksums
256a12f087109776df8b5928d7ebac47d6d71bf59820e03ff8f94f5fecdadd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Security for otsuvalidator 2.0.2

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.

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