MATLAB-style function argument validation for Python - clean, simple, and reliable.
Project description
func-validator
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 from func_validator import validate_func_args_at_runtime
-
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 (functions/callables) can be imported from the
func_validatornamespace
Usage
from typing import Annotated
from func_validator import validate_func_args
from func_validator.validators.numeric_arg_validators import ( MustBePositive,
MustBeNegative)
@validate_func_args
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file func_validator-0.14.0.tar.gz.
File metadata
- Download URL: func_validator-0.14.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
503f63196cf91b8be39fe8f50edba9b0cbacfefd968da468b46ceecc6f21d2c8
|
|
| MD5 |
2e55ebe2603a3f50c673863324bdd9d6
|
|
| BLAKE2b-256 |
b3d37f66e67b16ccca49474e329c02bdda995bc978cfff49ecc491554150b629
|
Provenance
The following attestation bundles were made for func_validator-0.14.0.tar.gz:
Publisher:
func-validator-publish.yml on patrickboateng/func-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
func_validator-0.14.0.tar.gz -
Subject digest:
503f63196cf91b8be39fe8f50edba9b0cbacfefd968da468b46ceecc6f21d2c8 - Sigstore transparency entry: 559535319
- Sigstore integration time:
-
Permalink:
patrickboateng/func-validator@fa941de548538b75f83fed828b5f36729c8da86f -
Branch / Tag:
refs/tags/v0.14.0 - Owner: https://github.com/patrickboateng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
func-validator-publish.yml@fa941de548538b75f83fed828b5f36729c8da86f -
Trigger Event:
push
-
Statement type:
File details
Details for the file func_validator-0.14.0-py3-none-any.whl.
File metadata
- Download URL: func_validator-0.14.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee563b19642913d0890b1744b57ae298636ff0aa5e51deacdd411e3291d47672
|
|
| MD5 |
c3bd5784934162cdbbeb23f960cabc1c
|
|
| BLAKE2b-256 |
6692ec506a15096da5c339bbc08dbd303421496faa74ca89ae0296680a7f5d30
|
Provenance
The following attestation bundles were made for func_validator-0.14.0-py3-none-any.whl:
Publisher:
func-validator-publish.yml on patrickboateng/func-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
func_validator-0.14.0-py3-none-any.whl -
Subject digest:
ee563b19642913d0890b1744b57ae298636ff0aa5e51deacdd411e3291d47672 - Sigstore transparency entry: 559535326
- Sigstore integration time:
-
Permalink:
patrickboateng/func-validator@fa941de548538b75f83fed828b5f36729c8da86f -
Branch / Tag:
refs/tags/v0.14.0 - Owner: https://github.com/patrickboateng
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
func-validator-publish.yml@fa941de548538b75f83fed828b5f36729c8da86f -
Trigger Event:
push
-
Statement type: