Skip to main content

LinkML Validator

Project description

LinkML Validator

Run tests PyPI

The LinkML Validator is a library for performing validation on data objects that conform to a given LinkML schema.

The Validator is initialized using a LinkML schema YAML, and is designed to allow for flexible validation where each type of validation is done by a plugin.

For example, JSONSchema validation is performed by JsonschemaValidationPlugin.

Motivation

The LinkML Validator is built with the following goals in mind:

  • the Validator should respond with parseable validation messages
  • the Validator should not break the validation process even if one object from a list of objects fail validation
  • the Validator should provide the ability to perform more than one type of validation on an object

Installation

python setup.py install

Running the LinkML Validator via CLI

To run the LinkML Validator,

linkml-validator --inputs <INPUT JSON> \
    --schema <SCHEMA YAML> \
    --output <OUTPUT>

You can pass filepath or a URL that points to the LinkML schema YAML.

Input data as a dictionary of objects

The input JSON can be a dictionary of objects keyed by the object type.

{
    "<OBJECT_TYPE>": [
        {

        }
    ]
}

Where the <OBJECT_TYPE> is the pythonic representation of a class defined in the schema YAML.

For example, consider examples/example_data1.json:

{
    "NamedThing": [
        {
            "id": "obj1",
            "name": "Object 1",
            "type": "X"
        },
        {
            "id": "obj2",
            "name": "Object 2",
            "type": "Y"
        }
    ]
}

In the above example, the NamedThing is the target_class, which is the pythonic representation of the class named thing as defined in the examples/example_schema.yaml.

You can run the validator on the above data as follows:

linkml-validator --inputs examples/example_data1.json \
    --schema examples/example_schema.yaml \
    --output examples/example_data1_validation_report.json

Input data as an array of ojbects

The input JSON can also be an array of objects:

[
    {},
    {}
]

In this case, one must also specify the object type via --target-class argument in the CLI.

For example, consider examples/example_data2.json:

[
    {
        "id": "obj1",
        "name": "Object 1",
        "type": "X"
    },
    {
        "id": "obj2",
        "name": "Object 2",
        "type": "Y"
    }
]

You can run the validator on the above data as follows:

linkml-validator --inputs examples/example_data2.json \
    --schema examples/example_schema.yaml \
    --output examples/example_data2_validation_report.json \
    --target-class NamedThing

Running selected plugins

To run only certain plugins as part of the validation,

linkml-validator --inputs data.json \
    --schema schema.yaml \
    --output validation_results.json \
    --plugins JsonschemaValidationPlugin

To perform strict validation,

linkml-validator --inputs data.json \
    --schema schema.yaml \
    --output validation_results.json \
    --plugins JsonschemaValidationPlugin \
    --strict

Under normal (default) mode, the validator will run all the checks defined in all referenced plugins on a given object.

When in strict mode, the validator will stop the validation for an object if even one of the plugins report a failed validation.

Using LinkML Validator as a module

You can use the linkml_validator.validator.Validator class directly in your codebase to perform validation on objects that you are working with.

The following code snippet provides a quick way of instantiating the Validator class and performing validation on an object:

from linkml_validator.validator import Validator

data_obj = {
    "id": "obj1",
    "name": "Object 1",
    "type": "X"
}
validator = Validator(schema="examples/example_schema.yaml")
validator.validate(obj=data_obj, target_class="NamedThing")

Note: The above code makes the assumption that there is a class named thing defined in the examples/example_schema.yaml and that NamedThing is its Pythonic representation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linkml_validator-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

linkml_validator-0.1.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file linkml_validator-0.1.0.tar.gz.

File metadata

  • Download URL: linkml_validator-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for linkml_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f817d3ddc16ac256a15efcf2ea1f623f91b2abc84bcd5b6a452d6d4e7655f95
MD5 48e00136b04cbef6cc625a1e9ac5c011
BLAKE2b-256 ffa2948a57ed995a725b793bcc78a6386d14827c3ebc3acdc8ba20a379c3cdf4

See more details on using hashes here.

Provenance

File details

Details for the file linkml_validator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: linkml_validator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for linkml_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7fd55963f9a942ffee2de3f0c24354cf0d4ea95118878dbe5e215c0d8a9ec7d5
MD5 d64ee7ede8c66a0460241ecc08bdc2e4
BLAKE2b-256 b5fd3fe20e6d45974516ee5dd892cae3f03c8a43a4468652b90847f3ac4641a9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page