Metadata-Version: 2.4
Name: func-validator
Version: 1.5.0
Summary: MATLAB-style function argument validation for Python - clean, simple, and reliable.
Author-email: Patrick Boateng <patrickboateng@patrickboateng.tech>
License: MIT License
        
        Copyright (c) 2025 func-validator
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: homepage, https://github.com/patrickboateng/func-validator
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# func-validator

[![Github](https://img.shields.io/badge/func--validator-000000?style=flat&logo=github&logoColor=white)](https://github.com/patrickboateng/func-validator)
[![PyPI Latest Release](https://img.shields.io/pypi/v/func-validator?style=flat&logo=pypi)](https://pypi.org/project/func-validator/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/func-validator.svg?logo=python&style=flat)](https://pypi.python.org/pypi/func-validator/)
[![Unit-Tests](https://github.com/patrickboateng/func-validator/actions/workflows/func-validator-unit-tests.yml/badge.svg)](https://github.com/patrickboateng/func-validator/actions/workflows/func-validator-unit-tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/patrickboateng/func-validator/badge.svg?branch=main)](https://coveralls.io/github/patrickboateng/func-validator?branch=main)
[![license](https://img.shields.io/pypi/l/func-validator?style=flat&logo=opensourceinitiative)](https://opensource.org/license/mit/)
[![Documentation Status](https://readthedocs.org/projects/func-validator/badge/?version=latest)](https://func-validator.readthedocs.io/en/latest/?badge=latest)

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

## Table of Contents

- [Installation](#installation)
- [Imports](#imports)
- [Usage](#usage)
- [Validators](#validators)
  - [Collection Validators](#collection-validators)
  - [DataType Validators](#datatype-validators)
  - [Numeric Validators](#numeric-validators)
  - [Text Validators](#text-validators)
  - [Dependent Argument Validator](#dependent-argument-validator)
- [License](#license)

## Installation

```shell
pip install func-validator
```

## Imports

- Import for the function decorator

  ```python
  from func_validator import validate_params
  ```

- Import for the validators

  ```python
  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:

    - [collection_arg_validators](#collection-validators)
    - [datatype_arg_validators](#datatype-validators)
    - [text_arg_validators](#text-validators)

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

## Usage

```python

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](https://func-validator.readthedocs.io/en/latest/)
for more examples.

### Collection Validators

<table>
    <tr>
        <td>MustBeMemberOf</td>
        <td>Validate that argument value is in a collection</td>
    </tr>
    <tr>
        <td>MustBeEmpty</td>
        <td>Validate that argument value is empty</td>
    </tr>
</table>

### DataType Validators

<table>
    <tr>
        <td>MustBeA</td>
        <td>Validates that the value is of the specified type</td>
    </tr>
</table>

### Numeric Validators

<table>
    <tr>
        <td>MustBePositive</td>
        <td>Validate that argument value is positive</td>
    </tr>
    <tr>
        <td>MustBeNegative</td>
        <td>Validate that argument value is negative</td>
    </tr>
</table>

### Text Validators

<table>
    <tr>
        <td>MustMatchRegex</td>
        <td>Validates that the value matches the provided regular expression.</td>
    </tr>
</table>

### Dependent Argument Validator

<table>
    <tr>
        <td>DependsOn</td>
        <td>
            Validates that the value of one argument depends on the value or 
            presence of another argument.
        </td>
    </tr>
</table>

## License

MIT License
