Skip to main content

MATLAB-style function argument validation for Python - clean, simple, and reliable.

Project description

func-validator

PyPI Latest Release PyPI pyversions Unit-Tests Coverage Status license

MATLAB-style function argument validation for Python - clean, simple, and reliable.

Table of Contents

Installation

$ pip install func-validator

Imports

  • Import for the function decorator
    >>> from func_validator import validate_func_args # or validate_func_args_at_runtime
    
  • Import for the validators
    >>> from func_validator import MustBeGreaterThan, MustMatchRegex
    

Usage

>>> from typing import Annotated

>>> from func_validator import (validate_func_args,
...                             MustBePositive,
...                             MustBeNegative)

>>> @validate_func_args  
... def func(a: Annotated[int, MustBePositive],
...          b: Annotated[float, MustBeNegative]):
...     return (a, b)

>>> func(10, -10)  # ✅ Correct
(10, -10)

>>> func(-10, -10)  # ❌ Wrong -10 is not positive and 10 is not negative
Traceback (most recent call last):
...
ValidationError: x=-10 must be > 0.0.

>>> func(0, -10)  # ❌ Wrong 0 is not positive
Traceback (most recent call last):
...
ValidationError: x=0 must be > 0.0.

Validators

This is not the exhaustive list for all validators, checkout the docs for more examples.

Collection Validators

MustBeMemberOf Validate that argument value is in a collection
MustBeEmpty Validate that argument value is empty

DataType Validators

MustBeA Validates that the value is of the specified type

Numeric Validators

MustBePositive Validate that argument value is positive
MustBeNegative Validate that argument value is negative

Text Validators

MustMatchRegex Validates that the value matches the provided regular expression.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

func_validator-0.11.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

func_validator-0.11.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file func_validator-0.11.0.tar.gz.

File metadata

  • Download URL: func_validator-0.11.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for func_validator-0.11.0.tar.gz
Algorithm Hash digest
SHA256 8de7932021a78c9f454f2c0939073c145d4b7481699e4bfe12955d8fb24dd1fd
MD5 519ffb917cbab96bdbc043957b2d814e
BLAKE2b-256 18063f2cf654b4bc44ba356292c5f85a43d78a8bd303375f333bf799f21e7937

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-0.11.0.tar.gz:

Publisher: func-validator-publish.yml on patrickboateng/func-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file func_validator-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for func_validator-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca8c37ee79483b016a96babf99495f4ba19c7c8389d42bb6ff8cee8813df7229
MD5 5dd5587e0823e7c989dcad183b3b4ec0
BLAKE2b-256 b704b7441362d48ee971212e2e1eaa4e222b52b4822e35984736fd9485dc2c40

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-0.11.0-py3-none-any.whl:

Publisher: func-validator-publish.yml on patrickboateng/func-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page