kohi


Namekohi JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/natanfeitosa/kohi#readme
SummaryA powerfull schema validator
upload_time2023-01-26 21:24:12
maintainer
docs_urlNone
authorNatan Santos
requires_python>=3.8,<4.0
license
keywords data validator schema json science
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# kohi

<p align="center">A powerfull schema validator</p>

![GitHub Repo stars](https://img.shields.io/github/stars/natanfeitosa/kohi)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/natanfeitosa/kohi/pytest.yml?label=Pytest&logo=github)
![GitHub](https://img.shields.io/github/license/natanfeitosa/kohi)
![PyPI - Format](https://img.shields.io/pypi/format/kohi)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/kohi)
![PyPI - Package Version](https://img.shields.io/pypi/v/kohi)
![PyPI - Downloads](https://img.shields.io/pypi/dm/kohi)
[![Open Source Helpers](https://www.codetriage.com/natanfeitosa/kohi/badges/users.svg)](https://www.codetriage.com/natanfeitosa/kohi)

## Instalation

Via Poetry:
```sh
poetry add kohi
```

Via PIP:
```sh
pip install kohi
```

Via GitHub (recommended only in dev env):
```sh
git clone https://github.com/natanfeitosa/kohi.git && cd kohi && pip install .
```

## Quickstart

To validate a type you can import your schema validator from `kohi` or `from kohi.<type> import <type>Schema`

e.g.

Let's check if a person's date of birth is a positive integer less than the current date — 2023 — and greater than or equal to 2005

```python
from kohi import NumberSchema
# from kohi.number import NumberSchema

n = NumberSchema().int().positive().lt(2023).gte(2005)

print(n.validate(2005)) # True
print(n.validate(2022)) # True
print(n.validate(2004)) # False
print(n.validate(2023)) # False

# You can see the errors generated in the last `validate` call just by accessing the `errors` property
# print(n.errors) # ['number must be less than 2022']
```

## Validators

* [`kohi.base.BaseSchema`](#baseschema)
> Only one base class for all schema validators
* [`kohi.number.NumberSchema`](#numberschema)
> or `kohi.NumberSchema`
* [`kohi.string.StringSchema`](#stringschema)
> or `kohi.StringSchema`
* [`kohi.enum.EnumSchema`](#enumschema)
> or `kohi.EnumSchema`

## Methods

### `BaseSchema`
* `add_validator(name, func): Self`
  > Add a custom data validator
* `validate(data): bool`
  > The method to be called when we validate the schema
* `reset(): None`
  > Reset error list
* `throw(): Self`
  > By default no errors are thrown, but when this method is chained a `ValidationError` will be thrown

### `NumberSchema`
inherits from [`BaseSchema`](#baseschema)
> By default validates int and float 

* `float(): Self`
  > Validate only `float`
* `int(): Self`
  > Validate only `int`
* `lt(num): Self`
  > Validates if the data is less than `num`
* `gt(num): Self`
  > Validates if the data is greater than `num`
* `lte(num): Self`
  > Validates if the data is less than or equal to `num`
* `gte(num): Self`
  > Validates if the data is greater than or equal to `num`
* `min(num): Self`
  > Just an alias for `gte(num)`
* `max(num): Self`
  > Just an alias for `lte(nun)`
* `positive(): Self`
  > Just an alias for `gt(0)`
* `negative(): Self`
  > Just an alias for `lt(0)`
* `nonpositive(): Self`
  > Just an alias for `lte(0)`
* `nonnegative(): Self`
  > Just an alias for `gte(0)`

### StringSchema
inherits from [`BaseSchema`](#baseschema)

* `min(min_length): Self`
  > Validate if the data len is greater than or equal to min_length
* `length(length): Self`
  > Validate if the data len equal to length
* `max(max_length): Self`
  > Validate if the data len is less than or equal to max_length
* `url(): Self`
  > Validate if the data is an url
* `uuid(): Self`
  > Validate if the data is a valid uuid
* `starts_with(text): Self`
  > Validate if the data starts with text
* `ends_with(text): Self`
  > Validate if the data ends with text

### EnumSchema
inherits from [`BaseSchema`](#baseschema)

* `one_of(opts): Self`
  > Validate if the data is in opts
* `not_one_of(opts): Self`
  > Validate that data is different from the values in opts

## Dev env

* install development dependencies
* check types using `mypy`
* run all tests using `pytest`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/natanfeitosa/kohi#readme",
    "name": "kohi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "data,validator,schema,json,science",
    "author": "Natan Santos",
    "author_email": "natansantosapps@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/18/b0058f6fb72b42f5899bde0cd407f64af93f8b6e6af84bebad92dfc054b9/kohi-0.3.0.tar.gz",
    "platform": null,
    "description": "\n# kohi\n\n<p align=\"center\">A powerfull schema validator</p>\n\n![GitHub Repo stars](https://img.shields.io/github/stars/natanfeitosa/kohi)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/natanfeitosa/kohi/pytest.yml?label=Pytest&logo=github)\n![GitHub](https://img.shields.io/github/license/natanfeitosa/kohi)\n![PyPI - Format](https://img.shields.io/pypi/format/kohi)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/kohi)\n![PyPI - Package Version](https://img.shields.io/pypi/v/kohi)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/kohi)\n[![Open Source Helpers](https://www.codetriage.com/natanfeitosa/kohi/badges/users.svg)](https://www.codetriage.com/natanfeitosa/kohi)\n\n## Instalation\n\nVia Poetry:\n```sh\npoetry add kohi\n```\n\nVia PIP:\n```sh\npip install kohi\n```\n\nVia GitHub (recommended only in dev env):\n```sh\ngit clone https://github.com/natanfeitosa/kohi.git && cd kohi && pip install .\n```\n\n## Quickstart\n\nTo validate a type you can import your schema validator from `kohi` or `from kohi.<type> import <type>Schema`\n\ne.g.\n\nLet's check if a person's date of birth is a positive integer less than the current date \u2014 2023 \u2014 and greater than or equal to 2005\n\n```python\nfrom kohi import NumberSchema\n# from kohi.number import NumberSchema\n\nn = NumberSchema().int().positive().lt(2023).gte(2005)\n\nprint(n.validate(2005)) # True\nprint(n.validate(2022)) # True\nprint(n.validate(2004)) # False\nprint(n.validate(2023)) # False\n\n# You can see the errors generated in the last `validate` call just by accessing the `errors` property\n# print(n.errors) # ['number must be less than 2022']\n```\n\n## Validators\n\n* [`kohi.base.BaseSchema`](#baseschema)\n> Only one base class for all schema validators\n* [`kohi.number.NumberSchema`](#numberschema)\n> or `kohi.NumberSchema`\n* [`kohi.string.StringSchema`](#stringschema)\n> or `kohi.StringSchema`\n* [`kohi.enum.EnumSchema`](#enumschema)\n> or `kohi.EnumSchema`\n\n## Methods\n\n### `BaseSchema`\n* `add_validator(name, func): Self`\n  > Add a custom data validator\n* `validate(data): bool`\n  > The method to be called when we validate the schema\n* `reset(): None`\n  > Reset error list\n* `throw(): Self`\n  > By default no errors are thrown, but when this method is chained a `ValidationError` will be thrown\n\n### `NumberSchema`\ninherits from [`BaseSchema`](#baseschema)\n> By default validates int and float \n\n* `float(): Self`\n  > Validate only `float`\n* `int(): Self`\n  > Validate only `int`\n* `lt(num): Self`\n  > Validates if the data is less than `num`\n* `gt(num): Self`\n  > Validates if the data is greater than `num`\n* `lte(num): Self`\n  > Validates if the data is less than or equal to `num`\n* `gte(num): Self`\n  > Validates if the data is greater than or equal to `num`\n* `min(num): Self`\n  > Just an alias for `gte(num)`\n* `max(num): Self`\n  > Just an alias for `lte(nun)`\n* `positive(): Self`\n  > Just an alias for `gt(0)`\n* `negative(): Self`\n  > Just an alias for `lt(0)`\n* `nonpositive(): Self`\n  > Just an alias for `lte(0)`\n* `nonnegative(): Self`\n  > Just an alias for `gte(0)`\n\n### StringSchema\ninherits from [`BaseSchema`](#baseschema)\n\n* `min(min_length): Self`\n  > Validate if the data len is greater than or equal to min_length\n* `length(length): Self`\n  > Validate if the data len equal to length\n* `max(max_length): Self`\n  > Validate if the data len is less than or equal to max_length\n* `url(): Self`\n  > Validate if the data is an url\n* `uuid(): Self`\n  > Validate if the data is a valid uuid\n* `starts_with(text): Self`\n  > Validate if the data starts with text\n* `ends_with(text): Self`\n  > Validate if the data ends with text\n\n### EnumSchema\ninherits from [`BaseSchema`](#baseschema)\n\n* `one_of(opts): Self`\n  > Validate if the data is in opts\n* `not_one_of(opts): Self`\n  > Validate that data is different from the values in opts\n\n## Dev env\n\n* install development dependencies\n* check types using `mypy`\n* run all tests using `pytest`\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A powerfull schema validator",
    "version": "0.3.0",
    "split_keywords": [
        "data",
        "validator",
        "schema",
        "json",
        "science"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e25047ffe2be5f7acd0714c69b08650cc192e58d33bcd5b84f3261a7b630d96a",
                "md5": "b2b1f751ba9bcbdda6a4ca10ddc16d4d",
                "sha256": "193c17c5841a4bc73faace7e21ea4a808822b28904218cd7b2da74b6c56cf808"
            },
            "downloads": -1,
            "filename": "kohi-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2b1f751ba9bcbdda6a4ca10ddc16d4d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 6532,
            "upload_time": "2023-01-26T21:24:10",
            "upload_time_iso_8601": "2023-01-26T21:24:10.844902Z",
            "url": "https://files.pythonhosted.org/packages/e2/50/47ffe2be5f7acd0714c69b08650cc192e58d33bcd5b84f3261a7b630d96a/kohi-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b18b0058f6fb72b42f5899bde0cd407f64af93f8b6e6af84bebad92dfc054b9",
                "md5": "5c918bad64f55696ee20b513b1430ee1",
                "sha256": "67416485d7cc144174e7759498c5710c99d384fd4c976e97e2c9d50c4f1bd554"
            },
            "downloads": -1,
            "filename": "kohi-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5c918bad64f55696ee20b513b1430ee1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 6242,
            "upload_time": "2023-01-26T21:24:12",
            "upload_time_iso_8601": "2023-01-26T21:24:12.979893Z",
            "url": "https://files.pythonhosted.org/packages/5b/18/b0058f6fb72b42f5899bde0cd407f64af93f8b6e6af84bebad92dfc054b9/kohi-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-26 21:24:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "natanfeitosa",
    "github_project": "kohi#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "kohi"
}
        
Elapsed time: 0.03441s