xdi-validator


Namexdi-validator JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryA standalone JSON Schema based validator for XDI files used to save XAS data aiming to be fully compliant with the XDI/1.0 specification..
upload_time2025-10-27 04:37:53
maintainerNone
docs_urlNone
authorNone
requires_python>=3.13
licenseNone
keywords validation xas xdi
VCS
bugtrack_url
requirements jsonschema
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI - Version](https://img.shields.io/pypi/v/xdi-validator?pypiBaseUrl=https%3A%2F%2Fpypi.org&style=flat-square)](https://pypi.org/project/xdi-validator/)
[![Building and testing](https://github.com/AAAlvesJr/XDI-Validator/actions/workflows/python-test.yml/badge.svg)](https://github.com/AAAlvesJr/XDI-Validator/actions/workflows/python-test.yml)

# XDI-Validator

## What is it?

XDI-Validator is a standalone JSON Schema based validator for XDI files.
XDI (*.xdi) is a format used to save XAS data. This validator aim to be
fully compliant with the XDI/1.0 specification, as detailed in the documents 
[XAS Data Interchange Format Draft Specification, version 1.0](https://github.com/XraySpectroscopy/XAS-Data-Interchange/blob/master/specification/xdi_spec.pdf)
and [Dictionary of XAS Data Interchange Metadata](https://github.com/XraySpectroscopy/XAS-Data-Interchange/blob/master/specification/xdi_dictionary.pdf).

## Usage 

As simple as it gets : 

```python
# import the functionality from the module
from xdi_validator import validate, XDIEndOfHeaderMissingError

# open the xdi file
with open('filename.xdi', 'r') as xdi_document:
    
    # Validate the file. If there is no end-of-header token
    # an exception is raised
    try:
        xdi_errors, xdi_dict = validate(xdi_document)
    except XDIEndOfHeaderMissingError as ex:
        print(ex.message)
        
    # check if there are errors
    if xdi_errors:
        print('XDI is invalid!')
        print(xdi_errors)
    else:
        print('XDI is valid!')
        print(xdi_dict)
    
```
Basically, the method `xdi_validator.validate()` the `*.xdi` file-like object and will return a dictionary with the found errors per each field, 
and a representation of the contents of the `*.xdi` as a dictionary. The dictionary of errors is organized in the following way. 
The keys are the path (`Namespace.tag`) of the invalid field, and the corresponding value is the list of errors.

Note: Sure, users can also to use the library for parsing and converting XDI files into json representation. 

Additionally, it is possible to convert a dictionary to XDI format and write it to file using the `xdi_validator.write_xdi()` function. 
Look the example below for a possible use case for this functionality:

```python
# import the functionality from the module
from xdi_validator import validate, write_xdi, XDIEndOfHeaderMissingError

# open the xdi file
xdi
with open('filename.xdi', 'r') as xdi_document:
    
    # Validate the file. If there is no end-of-header token
    # an exception is raised
    try:
        xdi_errors, xdi_dict = validate(xdi_document)
    except XDIEndOfHeaderMissingError as ex:
        print(ex.message)
        
# check if there are errors
if xdi_errors:
    print('XDI is invalid!')
    # use the information in xdi_errors to correct the data
    # in the generated xdi_dict 
    ...
    # write the corrected data to file
    errors = write_xdi('corrected_file.xdi', xdi_dict)
    if not errors:
        print('Corrected file saved.')
    else:
        print(errors)
else:
    print('XDI is valid!')
    print(xdi_dict)

```

## How to install?

XDI-Validator is available in PyPI. The project page is https://pypi.org/project/xdi-validator/.
To install XDI-Validator on your development environment, just issue the command:

```terminal
 pip install xdi-validator
```

To build and install from the source code do:

1. Clone the repository: `git clone https://github.com/AAAlvesJr/XDI-Validator.git`
2. Go the project directory: `cd XDI-Validator`
3. Build the package: `python3 -m build`
4. Install the wheel: `pip install dist/xdi_validator-{VERSION}-py3-none-any.whl`

where `VERSION` is the package version. 

## Source code

Access to the source code is granted via the project GitHub repository at the
url  https://github.com/AAAlvesJr/XDI-Validator.

## Dependencies 

XDI-Validator's only external dependency is [jsonschema](https://pypi.org/project/jsonschema/) package. 

## How to contribute 

Please, submit a pull request. PR adding new features should implement the correspondind unit test. 
Aside that, please, feel free to open issues for bugs and features requests. 

## License 

XDI-Validator is available under the MIT license. See the LICENSE file for more info.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xdi-validator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": "Antonio Augusto Alves Jr <aalvesju@gmail.com>",
    "keywords": "validation, xas, xdi",
    "author": null,
    "author_email": "Antonio Augusto Alves Jr <aalvesju@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/15/bb/c2cf7b468c93915847640c04deb1c0fc1d46f6ee24edfb11e04480347dc4/xdi_validator-1.3.0.tar.gz",
    "platform": null,
    "description": "[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI - Version](https://img.shields.io/pypi/v/xdi-validator?pypiBaseUrl=https%3A%2F%2Fpypi.org&style=flat-square)](https://pypi.org/project/xdi-validator/)\n[![Building and testing](https://github.com/AAAlvesJr/XDI-Validator/actions/workflows/python-test.yml/badge.svg)](https://github.com/AAAlvesJr/XDI-Validator/actions/workflows/python-test.yml)\n\n# XDI-Validator\n\n## What is it?\n\nXDI-Validator is a standalone JSON Schema based validator for XDI files.\nXDI (*.xdi) is a format used to save XAS data. This validator aim to be\nfully compliant with the XDI/1.0 specification, as detailed in the documents \n[XAS Data Interchange Format Draft Specification, version 1.0](https://github.com/XraySpectroscopy/XAS-Data-Interchange/blob/master/specification/xdi_spec.pdf)\nand [Dictionary of XAS Data Interchange Metadata](https://github.com/XraySpectroscopy/XAS-Data-Interchange/blob/master/specification/xdi_dictionary.pdf).\n\n## Usage \n\nAs simple as it gets : \n\n```python\n# import the functionality from the module\nfrom xdi_validator import validate, XDIEndOfHeaderMissingError\n\n# open the xdi file\nwith open('filename.xdi', 'r') as xdi_document:\n    \n    # Validate the file. If there is no end-of-header token\n    # an exception is raised\n    try:\n        xdi_errors, xdi_dict = validate(xdi_document)\n    except XDIEndOfHeaderMissingError as ex:\n        print(ex.message)\n        \n    # check if there are errors\n    if xdi_errors:\n        print('XDI is invalid!')\n        print(xdi_errors)\n    else:\n        print('XDI is valid!')\n        print(xdi_dict)\n    \n```\nBasically, the method `xdi_validator.validate()` the `*.xdi` file-like object and will return a dictionary with the found errors per each field, \nand a representation of the contents of the `*.xdi` as a dictionary. The dictionary of errors is organized in the following way. \nThe keys are the path (`Namespace.tag`) of the invalid field, and the corresponding value is the list of errors.\n\nNote: Sure, users can also to use the library for parsing and converting XDI files into json representation. \n\nAdditionally, it is possible to convert a dictionary to XDI format and write it to file using the `xdi_validator.write_xdi()` function. \nLook the example below for a possible use case for this functionality:\n\n```python\n# import the functionality from the module\nfrom xdi_validator import validate, write_xdi, XDIEndOfHeaderMissingError\n\n# open the xdi file\nxdi\nwith open('filename.xdi', 'r') as xdi_document:\n    \n    # Validate the file. If there is no end-of-header token\n    # an exception is raised\n    try:\n        xdi_errors, xdi_dict = validate(xdi_document)\n    except XDIEndOfHeaderMissingError as ex:\n        print(ex.message)\n        \n# check if there are errors\nif xdi_errors:\n    print('XDI is invalid!')\n    # use the information in xdi_errors to correct the data\n    # in the generated xdi_dict \n    ...\n    # write the corrected data to file\n    errors = write_xdi('corrected_file.xdi', xdi_dict)\n    if not errors:\n        print('Corrected file saved.')\n    else:\n        print(errors)\nelse:\n    print('XDI is valid!')\n    print(xdi_dict)\n\n```\n\n## How to install?\n\nXDI-Validator is available in PyPI. The project page is https://pypi.org/project/xdi-validator/.\nTo install XDI-Validator on your development environment, just issue the command:\n\n```terminal\n pip install xdi-validator\n```\n\nTo build and install from the source code do:\n\n1. Clone the repository: `git clone https://github.com/AAAlvesJr/XDI-Validator.git`\n2. Go the project directory: `cd XDI-Validator`\n3. Build the package: `python3 -m build`\n4. Install the wheel: `pip install dist/xdi_validator-{VERSION}-py3-none-any.whl`\n\nwhere `VERSION` is the package version. \n\n## Source code\n\nAccess to the source code is granted via the project GitHub repository at the\nurl  https://github.com/AAAlvesJr/XDI-Validator.\n\n## Dependencies \n\nXDI-Validator's only external dependency is [jsonschema](https://pypi.org/project/jsonschema/) package. \n\n## How to contribute \n\nPlease, submit a pull request. PR adding new features should implement the correspondind unit test. \nAside that, please, feel free to open issues for bugs and features requests. \n\n## License \n\nXDI-Validator is available under the MIT license. See the LICENSE file for more info.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A standalone JSON Schema based validator for XDI files used to save XAS data aiming to be fully compliant with the XDI/1.0 specification..",
    "version": "1.3.0",
    "project_urls": {
        "Documentation": "https://github.com/AAAlvesJr/XDI-Validator",
        "Homepage": "https://github.com/AAAlvesJr/XDI-Validator",
        "Repository": "https://github.com/AAAlvesJr/XDI-Validator.git"
    },
    "split_keywords": [
        "validation",
        " xas",
        " xdi"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d6fbd42f188492f87020d9eec35ec9f0851fb15c12e6b8c1ef23cb033afe8539",
                "md5": "f63309c9cc2870c2f54388c8bdf96969",
                "sha256": "e9a714a9a52ea736a215ab11dea0c2efdfb11f3c48f6f3c04ff757b76d35878a"
            },
            "downloads": -1,
            "filename": "xdi_validator-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f63309c9cc2870c2f54388c8bdf96969",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 10876,
            "upload_time": "2025-10-27T04:37:51",
            "upload_time_iso_8601": "2025-10-27T04:37:51.861536Z",
            "url": "https://files.pythonhosted.org/packages/d6/fb/d42f188492f87020d9eec35ec9f0851fb15c12e6b8c1ef23cb033afe8539/xdi_validator-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "15bbc2cf7b468c93915847640c04deb1c0fc1d46f6ee24edfb11e04480347dc4",
                "md5": "e71fbcae34def68849b6eb51fe28c408",
                "sha256": "c22c76dfbfce2e4655e4d050e03931409506773258479f29ce4fb4ef4453b103"
            },
            "downloads": -1,
            "filename": "xdi_validator-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e71fbcae34def68849b6eb51fe28c408",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 26221,
            "upload_time": "2025-10-27T04:37:53",
            "upload_time_iso_8601": "2025-10-27T04:37:53.056106Z",
            "url": "https://files.pythonhosted.org/packages/15/bb/c2cf7b468c93915847640c04deb1c0fc1d46f6ee24edfb11e04480347dc4/xdi_validator-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-27 04:37:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AAAlvesJr",
    "github_project": "XDI-Validator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "jsonschema",
            "specs": [
                [
                    ">=",
                    "4.23.0"
                ]
            ]
        }
    ],
    "lcname": "xdi-validator"
}
        
Elapsed time: 2.46819s