Skip to main content

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

Project description

func-validator

Github PyPI Latest Release PyPI pyversions Unit-Tests Coverage Status license Documentation Status

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_params
    
  • Import for the validators

    from func_validator import MustBeGreaterThan, MustMatchRegex 
    from func_validator.validators.numeric_arg_validators import MustBeGreaterThan
    

    There are 3 other modules you can import validators from, namely:

[!NOTE] All validator objects can be imported from the func_validator namespace

Usage

from typing import Annotated
from func_validator import validate_params
from func_validator.validators.numeric_arg_validators import (MustBePositive,
                                                              MustBeNegative)


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


func(10, -10)   # ✅ Correct

func(-10, -10)  # ❌ Wrong -10 is not positive and 10 is not negative
# A validation error is raised with a message.

func(0, -10)    # ❌ Wrong 0 is not positive
# A validation error is raised with a message.

func(20, 10)    # ❌ Wrong 10 is not negative
# A validation error is raised with a message.

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-1.1.1.tar.gz (13.4 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-1.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for func_validator-1.1.1.tar.gz
Algorithm Hash digest
SHA256 3d41ab0e6cf0d35dc98887c8c63d35cf8a1b4f74ff596c9d76b2f8f17ab5ecc4
MD5 bc5c288e0fda887d5034d2ef013319a4
BLAKE2b-256 930e36e38318f2a5a6c4f93accdac6d47f25f50eba9d2bd905ac0780906314eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-1.1.1.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-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: func_validator-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for func_validator-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 986ab0bb6c130df1aa310cac9844906685c34111920ae7ab161a1bc25a017cd6
MD5 2adbd7c7a72355733b93bd4605b88e94
BLAKE2b-256 cdc331472a38b0fcea5dfa09c3e1ab37fcee97fda1889399e1f63b1e754ac1c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for func_validator-1.1.1-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