Skip to main content

License: MIT PyPI - Version Building and testing DOI

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 and Dictionary of XAS Data Interchange Metadata.

Usage

As simple as it gets :

# 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:

# 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:

 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 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.

Metadata

Release files for xdi-validator 1.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xdi-validator 1.5.1
File Size Uploaded
xdi_validator-1.5.1.tar.gz 34.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xdi-validator 1.5.1
File Interpreter ABI Platform
xdi_validator-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.2 kB

Release files / xdi_validator-1.5.1.tar.gz

Download URL xdi_validator-1.5.1.tar.gz
Size 34.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dd23239d4a0ee0fa74fa6f52010febb443dfa4a0975222bc44a5de60e9cab471
BLAKE2b-256 checksum
How to use checksums
9960862e52d5cec45c6b01a592b5deb8faee44b20e6b6fd18b60b3844da69449
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xdi_validator-1.5.1-py3-none-any.whl

Download URL xdi_validator-1.5.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3170b4efb0420a81ad944ae336f11f7625fb7961ef4d0a239886b6e42b746aa4
BLAKE2b-256 checksum
How to use checksums
76d8b9a91ecaa3ec037a686f7fc64d2f8e87a5b11802d35f2a20d3dd3089b245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page