{"id":16426286,"url":"https://github.com/reala10n/validit","last_synced_at":"2025-03-28T22:30:46.109Z","repository":{"id":45162519,"uuid":"370490899","full_name":"RealA10N/validit","owner":"RealA10N","description":"Easily define configuration file structures, and validate files using the templates. 🍒📂","archived":false,"fork":false,"pushed_at":"2023-09-14T01:09:01.000Z","size":719,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T16:10:32.913Z","etag":null,"topics":["config","configuration","json","pip","pypi","pypi-package","python","python3","python36","template","templates","toml","toml-config","toml-parsing","toml-validation","validit","yaml","yaml-configuration","yml","yml-configuration"],"latest_commit_sha":null,"homepage":"https://tinyurl.com/validit-wiki","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RealA10N.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-24T21:38:12.000Z","updated_at":"2022-01-04T14:49:58.000Z","dependencies_parsed_at":"2024-10-28T15:28:47.892Z","dependency_job_id":"39783b9d-1b8d-48bf-b875-b60df27a36e0","html_url":"https://github.com/RealA10N/validit","commit_stats":{"total_commits":173,"total_committers":1,"mean_commits":173.0,"dds":0.0,"last_synced_commit":"e9325de467521c67f59c94835a1fcbdf70e93222"},"previous_names":["reala10n/configtemplate"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealA10N%2Fvalidit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealA10N%2Fvalidit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealA10N%2Fvalidit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealA10N%2Fvalidit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RealA10N","download_url":"https://codeload.github.com/RealA10N/validit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246109569,"owners_count":20724898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration","json","pip","pypi","pypi-package","python","python3","python36","template","templates","toml","toml-config","toml-parsing","toml-validation","validit","yaml","yaml-configuration","yml","yml-configuration"],"created_at":"2024-10-11T08:08:21.418Z","updated_at":"2025-03-28T22:30:45.861Z","avatar_url":"https://github.com/RealA10N.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# validit \u003c!-- omit in toc --\u003e\n\n[![Test](https://img.shields.io/github/workflow/status/reala10n/validit/%E2%9C%94%20Test?label=test)](https://github.com/RealA10N/validit/actions/workflows/test.yaml)\n[![PyPI](https://img.shields.io/pypi/v/validit)](https://pypi.org/project/validit/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/validit)](https://pypi.org/project/validit/)\n[![GitHub Repo stars](https://img.shields.io/github/stars/reala10n/validit?style=social)](https://github.com/RealA10N/validit)\n\n_Easily define configuration file structures, and validate files using the templates. 🍒📂_\n\n- [Installation](#installation)\n  - [Support for additional file formats](#support-for-additional-file-formats)\n- [Usage](#usage)\n  - [Defining a template](#defining-a-template)\n  - [Validating data](#validating-data)\n    - [Validating data from files](#validating-data-from-files)\n- [Using validit as a dependency](#using-validit-as-a-dependency)\n\n## Installation\n\n**validit** is tested on CPython 3.6, 3.7, 3.8, and 3.9.\nSimply install using pip:\n\n```bash\n$ (sudo) pip install validit\n```\n\n### Support for additional file formats\n\nBy default, _validit_ only supports `JSON` configuration files, or\nalready loaded data (not directly from a configuration file). However, using\nadditional dependencies, _validit_ supports the following file formats:\n\n- `JSON`\n- `YAML`\n- `TOML`\n\nTo install _validit_ with the additional required dependencies to support\nyour preferred file format, use:\n\n```yaml\npip install validit[yaml]        # install dependencies for yaml files\npip install validit[toml]        # toml files\npip install validit[json,toml]   # json and toml files\npip install validit[all]         # all available file formats\n```\n\n## Usage\n\n### Defining a template\n\nTo create a template, you will need the basic `Template` module, and usually the\nother three basic modules `TemplateList`, `TemplateDict`, and `Optional`.\n\nIn the following example, we will create a basic template that represents a single user:\n\n```python\nfrom validit import Template, TemplateList, TemplateDict, Optional\n\nTemplateUser = TemplateDict(            # a dictionary with 2 required values\n    username=Template(str),             # username must be a string\n    passcode=Template(int, str),        # can be a string or an integer.\n    nickname=Optional(Template(str)),   # optional - if provided, must be a string.\n)\n```\n\n### Validating data\n\nTo validate your data with a template, you should use the `Validate` object.\n\n```python\nfrom validit import Template, TemplateDict, Optional, Validate\n\ntemplate = TemplateDict(\n    username=Template(str),\n    passcode=Template(int, str),\n    nickname=Optional(Template(str)),\n)\n\ndata = {\n    'username': 'RealA10N',\n    'passcode': 123,\n}\n\nvalid = Validate(template, data)\nif valid.errors:            # if one or more errors found\n    print(valid.errors)     # print errors to console\n    exit(1)                 # exit the script with exit code 1\n\nelse:                       # if data matches the template\n    run_script(valid.data)  # run the script with the loaded data\n```\n\n#### Validating data from files\n\nIf your data is stored in a file, it is possible to use the `ValidateFromJSON`,\n`ValidateFromYAML` or `ValidateFromTOML` objects instead:\n\n```python\nfrom validit import Template, TemplateDict, Optional, ValidateFromYAML\n\nfilepath = '/path/to/data.yaml'\ntemplate = TemplateDict(\n    username=Template(str),\n    passcode=Template(int, str),\n    nickname=Optional(Template(str)),\n)\n\nwith open(filepath, 'r') as file:\n    # load and validate data from the file\n    valid = ValidateFromYAML(file, template)\n    \nif valid.errors:            # if one or more errors found\n    print(valid.errors)     # print errors to console\n    exit(1)                 # exit the script with exit code 1\n\nelse:                       # if data matches the template\n    run_script(valid.data)  # run the script with the loaded data\n```\n\n## Using validit as a dependency\n\n_validit_ is still under active development, and some core features\nmay change substantially in the near future.\n\nIf you are planning to use _validit_ as a dependency for your project,\nwe highly recommend specifying the exact version of the module you are using\nin the `requirements.txt` file or `setup.py` scripts.\n\nFor example, to pinpoint version _v1.3.2_ use the following line in your\n`requirements.txt` file:\n\n```yaml\nvalidit==1.3.2\nvalidit[yaml]==1.3.2     # If using extra file formats\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freala10n%2Fvalidit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freala10n%2Fvalidit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freala10n%2Fvalidit/lists"}