vval


Namevval JSON
Version 2.1.7 PyPI version JSON
download
home_pagehttps://github.com/munozarturo/vval
SummaryInput validation in Python
upload_time2024-07-15 15:57:14
maintainerNone
docs_urlNone
authorArturo Munoz
requires_python>=3.11
licenseNone
keywords validation
VCS
bugtrack_url
requirements varname typing_inspect
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://www.munozarturo.com/assets/vval/logo-github-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://www.munozarturo.com/assets/vval/logo-github-light.svg">
    <img alt="vval" src="https://www.munozarturo.com/assets/vval/logo-github-light.svg" width="50%" height="40%">
  </picture>
</div>

<!-- omit from toc -->
# vval: value validation

The `vval` module provides functions for input validation in python.

<!-- omit from toc -->
## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
  - [Basic Type Validation](#basic-type-validation)
  - [Iterable Validation](#iterable-validation)
  - [Option Validation](#option-validation)
  - [Filter Validation](#filter-validation)
- [Functionality Examples](#functionality-examples)
- [Notes](#notes)
- [Development and Publishing](#development-and-publishing)
  - [Testing](#testing)
  - [CI/CD](#cicd)
  - [Publishing a New Version](#publishing-a-new-version)
  - [Manual Publishing (if needed)](#manual-publishing-if-needed)

## Installation

```bash
pip install vval
```

## Usage

Import and use the `validate`, `validate_iterable`, `validate_option`, and `validate_filter` functions from the `vval` module.

### Basic Type Validation

```python
from typing import Union
from vval import validate

def f(x: int | str) -> None:
    validate(x, (int, str))
    ...

def g(x: Union[int, float]) -> None:
    validate(x, Union[int, float])
    ...

def h(x: Union[list, tuple] | dict | set) -> None:
    validate(x, (Union[list, tuple], dict, set))
    ...
```

### Iterable Validation

```python
from typing import Callable, Union
from vval import validate_iterable

def i(x: list[int | str | dict]) -> None:
    validate_iterable(x, (int, str, dict))
    ...

def j(x: list[int | str | dict | Union[float, Callable]]) -> None:
    validate_iterable(x, (int, str, dict, Union[float, Callable]))
    ...
```

### Option Validation

```python
from vval import validate_option

def k(x: str) -> None:
    validate_option(x, ["apple", "banana", "cherry"])
    ...
```

### Filter Validation

```python
from vval import validate_filter

def positive_filter(value):
    return value > 0

def l(x: int) -> None:
    validate_filter(x, positive_filter)
    ...
```

## Functionality Examples

```python
from vval import validate

y: list = [1, 2, 3]
validate(y, list) # True

x: list = [1, 2, 3]
validate(x, int) # Raises TypeError: Expected 'int' for `x`, got: 'list'.
```

## Notes

- The API is still experimental and subject to changes.
- Will not validate beyond a certain depth.
- Will not validate generic types (except Union).

Currently provided functions:

- `validate`: Validate that an element is of a specified type.
- `validate_iterable`: Validate that all elements in an iterable are of a specified type.
- `validate_option`: Validates that a value is among a set of options.
- `validate_filter`: Validates that a value passes a specified filter function.

## Development and Publishing

### Testing

Run tests locally:

```bash
pip install .[dev]
pytest
```

### CI/CD

This project uses GitHub Actions for Continuous Integration and Continuous Deployment:

1. **Pull Request Checks**: Automatically run tests on all pull requests to the main branch.
2. **Automated Publishing**: Triggers package build and publication to PyPI when a new version tag is pushed.

### Publishing a New Version

1. Create a new branch for the version bump:

   ```bash
   git checkout -b bump-version-x.y.z
   ```

2. Update the version in `setup.py` following [Semantic Versioning](https://semver.org/).

3. Commit changes:

   ```bash
   git add setup.py
   git commit -m "pack: bump version to x.y.z"
   ```

4. Push the branch and create a pull request:

   ```bash
   git push origin bump-version-x.y.z
   ```

   Then create a pull request on GitHub from this branch to main.

5. After the pull request is approved and merged, checkout and pull the updated main branch:

   ```bash
   git checkout main
   git pull origin main
   ```

6. Create and push a new tag:

   ```bash
   git tag vx.y.z
   git push origin vx.y.z
   ```

   Replace `x.y.z` with the new version number.

7. The GitHub Action will automatically build and publish the new version to PyPI.

### Manual Publishing (if needed)

Prerequisites:

```bash
pip install --upgrade setuptools wheel twine build
```

Build and publish:

```bash
rm -rf dist build *.egg-info
python -m build
twine check dist/*
twine upload dist/*
```

For TestPyPI (optional):

```bash
twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ wreqs
```

Note: Manual publishing should only be necessary if the automated process fails.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/munozarturo/vval",
    "name": "vval",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "validation",
    "author": "Arturo Munoz",
    "author_email": "munoz.arturoroman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/82/a5/7c2303cbcf839549e7ca6f12f8d985e55038de0b2ceb375705ae85051621/vval-2.1.7.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <picture>\n    <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://www.munozarturo.com/assets/vval/logo-github-dark.svg\">\n    <source media=\"(prefers-color-scheme: light)\" srcset=\"https://www.munozarturo.com/assets/vval/logo-github-light.svg\">\n    <img alt=\"vval\" src=\"https://www.munozarturo.com/assets/vval/logo-github-light.svg\" width=\"50%\" height=\"40%\">\n  </picture>\n</div>\n\n<!-- omit from toc -->\n# vval: value validation\n\nThe `vval` module provides functions for input validation in python.\n\n<!-- omit from toc -->\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Type Validation](#basic-type-validation)\n  - [Iterable Validation](#iterable-validation)\n  - [Option Validation](#option-validation)\n  - [Filter Validation](#filter-validation)\n- [Functionality Examples](#functionality-examples)\n- [Notes](#notes)\n- [Development and Publishing](#development-and-publishing)\n  - [Testing](#testing)\n  - [CI/CD](#cicd)\n  - [Publishing a New Version](#publishing-a-new-version)\n  - [Manual Publishing (if needed)](#manual-publishing-if-needed)\n\n## Installation\n\n```bash\npip install vval\n```\n\n## Usage\n\nImport and use the `validate`, `validate_iterable`, `validate_option`, and `validate_filter` functions from the `vval` module.\n\n### Basic Type Validation\n\n```python\nfrom typing import Union\nfrom vval import validate\n\ndef f(x: int | str) -> None:\n    validate(x, (int, str))\n    ...\n\ndef g(x: Union[int, float]) -> None:\n    validate(x, Union[int, float])\n    ...\n\ndef h(x: Union[list, tuple] | dict | set) -> None:\n    validate(x, (Union[list, tuple], dict, set))\n    ...\n```\n\n### Iterable Validation\n\n```python\nfrom typing import Callable, Union\nfrom vval import validate_iterable\n\ndef i(x: list[int | str | dict]) -> None:\n    validate_iterable(x, (int, str, dict))\n    ...\n\ndef j(x: list[int | str | dict | Union[float, Callable]]) -> None:\n    validate_iterable(x, (int, str, dict, Union[float, Callable]))\n    ...\n```\n\n### Option Validation\n\n```python\nfrom vval import validate_option\n\ndef k(x: str) -> None:\n    validate_option(x, [\"apple\", \"banana\", \"cherry\"])\n    ...\n```\n\n### Filter Validation\n\n```python\nfrom vval import validate_filter\n\ndef positive_filter(value):\n    return value > 0\n\ndef l(x: int) -> None:\n    validate_filter(x, positive_filter)\n    ...\n```\n\n## Functionality Examples\n\n```python\nfrom vval import validate\n\ny: list = [1, 2, 3]\nvalidate(y, list) # True\n\nx: list = [1, 2, 3]\nvalidate(x, int) # Raises TypeError: Expected 'int' for `x`, got: 'list'.\n```\n\n## Notes\n\n- The API is still experimental and subject to changes.\n- Will not validate beyond a certain depth.\n- Will not validate generic types (except Union).\n\nCurrently provided functions:\n\n- `validate`: Validate that an element is of a specified type.\n- `validate_iterable`: Validate that all elements in an iterable are of a specified type.\n- `validate_option`: Validates that a value is among a set of options.\n- `validate_filter`: Validates that a value passes a specified filter function.\n\n## Development and Publishing\n\n### Testing\n\nRun tests locally:\n\n```bash\npip install .[dev]\npytest\n```\n\n### CI/CD\n\nThis project uses GitHub Actions for Continuous Integration and Continuous Deployment:\n\n1. **Pull Request Checks**: Automatically run tests on all pull requests to the main branch.\n2. **Automated Publishing**: Triggers package build and publication to PyPI when a new version tag is pushed.\n\n### Publishing a New Version\n\n1. Create a new branch for the version bump:\n\n   ```bash\n   git checkout -b bump-version-x.y.z\n   ```\n\n2. Update the version in `setup.py` following [Semantic Versioning](https://semver.org/).\n\n3. Commit changes:\n\n   ```bash\n   git add setup.py\n   git commit -m \"pack: bump version to x.y.z\"\n   ```\n\n4. Push the branch and create a pull request:\n\n   ```bash\n   git push origin bump-version-x.y.z\n   ```\n\n   Then create a pull request on GitHub from this branch to main.\n\n5. After the pull request is approved and merged, checkout and pull the updated main branch:\n\n   ```bash\n   git checkout main\n   git pull origin main\n   ```\n\n6. Create and push a new tag:\n\n   ```bash\n   git tag vx.y.z\n   git push origin vx.y.z\n   ```\n\n   Replace `x.y.z` with the new version number.\n\n7. The GitHub Action will automatically build and publish the new version to PyPI.\n\n### Manual Publishing (if needed)\n\nPrerequisites:\n\n```bash\npip install --upgrade setuptools wheel twine build\n```\n\nBuild and publish:\n\n```bash\nrm -rf dist build *.egg-info\npython -m build\ntwine check dist/*\ntwine upload dist/*\n```\n\nFor TestPyPI (optional):\n\n```bash\ntwine upload --repository testpypi dist/*\npip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ wreqs\n```\n\nNote: Manual publishing should only be necessary if the automated process fails.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Input validation in Python",
    "version": "2.1.7",
    "project_urls": {
        "Bug Reports": "https://github.com/munozarturo/vval/issues",
        "Homepage": "https://github.com/munozarturo/vval",
        "Source": "https://github.com/munozarturo/vval/"
    },
    "split_keywords": [
        "validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e87b69799e11815f93519f2b468601863b30a8f9023e2e7ebf44efafcba1afb",
                "md5": "7b20bb57eaf64a03b3262b022deeb888",
                "sha256": "6e7b8017e9cc46a79a0a207f9e91193abf068ddbfcd6762ef7290bdd6e3590ec"
            },
            "downloads": -1,
            "filename": "vval-2.1.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b20bb57eaf64a03b3262b022deeb888",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 6205,
            "upload_time": "2024-07-15T15:57:13",
            "upload_time_iso_8601": "2024-07-15T15:57:13.371939Z",
            "url": "https://files.pythonhosted.org/packages/9e/87/b69799e11815f93519f2b468601863b30a8f9023e2e7ebf44efafcba1afb/vval-2.1.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82a57c2303cbcf839549e7ca6f12f8d985e55038de0b2ceb375705ae85051621",
                "md5": "4130baaad425a6b27abd9cd9252df60d",
                "sha256": "4a74cbca4540cbd25d4ffbff1a329420d53092488bb01a442f02cf115dd63a26"
            },
            "downloads": -1,
            "filename": "vval-2.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "4130baaad425a6b27abd9cd9252df60d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 9664,
            "upload_time": "2024-07-15T15:57:14",
            "upload_time_iso_8601": "2024-07-15T15:57:14.808746Z",
            "url": "https://files.pythonhosted.org/packages/82/a5/7c2303cbcf839549e7ca6f12f8d985e55038de0b2ceb375705ae85051621/vval-2.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-15 15:57:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "munozarturo",
    "github_project": "vval",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "varname",
            "specs": [
                [
                    "==",
                    "0.11.0"
                ]
            ]
        },
        {
            "name": "typing_inspect",
            "specs": [
                [
                    "==",
                    "0.8.0"
                ]
            ]
        }
    ],
    "lcname": "vval"
}
        
Elapsed time: 0.73732s