pyschematron


Namepyschematron JSON
Version 1.1.3 PyPI version JSON
download
home_pageNone
SummarySchematron validation in Python.
upload_time2024-12-21 12:29:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords schematron xml validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ############
PySchematron
############
This is a library package for Schematron validation in Python.

Schematron is a schema language used to validate XML documents.
A Schematron schema is defined as an XML containing various assertions to validate a target XML document.
If the XML you wish to validate passes all the Schematron assertions,
your XML is considered valid according to the Schematron schema.
Complete validation results are offered using the Schematron Validation Report Language,
a loose definition of an XML based validation report.

There are various versions of Schematron available.
This library only supports the latest version of Schematron,
`ISO/IEC 19757-3:2020 <https://www.iso.org/standard/74515.html>`_, with a few limitations (see below).

Currently, this library only supports a pure Python mode of Schematron validation.
In this pure Python mode we load the Schematron into an internal representation and apply that to an XML.
The advantage of such direct evaluation is that it offers superior performance compared to an XSLT
transformation based evaluation.
The disadvantage is that it only supports XPath expressions and does not support XSLT functions.

In the future we hope to expand this library with an XSLT transformation based processing.
Unfortunately XSLT transformations require an XSLT processor,
which is currently not available in Python for XSLT >= 2.0.

A few similar packages to this software in other languages are
`node-schematron <https://github.com/wvbe/node-schematron#readme>`_ in Javascript, and
`ph-schematron <http://phax.github.io/ph-schematron/>`_ in Java.

For all XPath expressions this package uses the
`elementpath <https://github.com/sissaschool/elementpath>`_ library supporting XPath 1.0, 2.0, 3.0 and 3.1 selectors.

Please note that, as of this writing, this package only supports Python 3.12.
Older Python versions are not supported due to missing functionality (Python syntax primarily).
Newer versions will be supported in due time.

**********
Python API
**********
To use the Python API, install the project like any other Python project, e.g. using ``pip install pyschematron``.

After that you can use:

.. code:: python

    from pyschematron import validate_document

    result = validate_document(<xml_document.xml>, <schematron_schema.sch>)

    svrl = result.get_svrl()
    is_valid = result.is_valid()


To process multiple documents with the same Schematron schema, you can use:

.. code:: python

    from pyschematron import validate_document

    documents = [...]
    schema = <schema.sch>

    results = validate_documents(documents, schema)


For more examples, or examples on how to use different parts of the API, please see the `demo_*` files in the
`scripts` directory.


**********************
Command Line Interface
**********************
To use the command line interface, first install the application using pip: ``pip install pyschematron``.
Afterwards, you can use the command ``pyschematron`` to validate your documents.
Use ``pyschematron --help`` to see the command line options.


*************
Functionality
*************
This library offers a basic implementation of Schematron using a pure Python "direct mode" evaluation method.

Direct mode evaluation
======================
The direct mode evaluation allows for basic validity checks using all XPath functionality of Schematron.

When applied to a document, the direct mode evaluation follows this procedure to validate a document:

#. Read in the Schematron from either a document or a string.
   In this phase the document is loaded into an AST (abstract syntax tree).
   All ``<includes />`` are resolved and inlined into the AST.
   All ``<extends />`` are loaded but not fully resolved at this stage.
#. Recreate the AST without abstract patterns and rules.
   In this phase we process the AST to create a concrete set of patterns and rules.
   All ``<extends />`` are resolved, abstract patterns are instantiated,
   and redundant abstract rules and patterns are removed.
#. Phase selection, we limit the AST to only include patterns and phases limited to the selected phase.
#. Query binding, we determine the query binding language to use.
   This library only supports ``xslt``, ``xslt2``, ``xslt3``, ``xpath``, ``xpath2``, ``xpath3``, and ``xpath31``,
   where all ``xslt`` variations are limited to XPath expressions only.
#. Apply the bound schema to an XML document to validate.


Custom functions
----------------
With the current direct mode evaluation method, custom XSLT functions in your Schematron (``<xsl:function>``) are not supported.
Custom Python functions are supported however. View the `demo_custom_functions.py` in the `scripts` directory for examples.


Compliance
----------
The direct mode evaluation supports most of the `ISO/IEC 19757-3:2020 <https://www.iso.org/standard/74515.html>`_ standard, with a few exceptions.
All Schematron specific elements are supported, except for XSLT elements.

In terms of attributes, the ``@documents`` attribute of the ``<assert />`` tag is not supported.
Furthermore, ``@icon``, ``@see``, ``@fpi``, ``@flag``, and ``@role`` are loaded but not used.

Note that the ISO Schematron applies rules to:

- Elements (*)
- Attributes (@*)
- Root node (/)
- Comments (comment())
- Processing instructions (processing-instruction())

But it does not apply rules to text nodes.

If there are any problems, please open a Github issue.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyschematron",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "Schematron, XML validation",
    "author": null,
    "author_email": "Robbert Harms <robbert@xkls.nl>",
    "download_url": "https://files.pythonhosted.org/packages/cf/0a/9d597427e75e5dd0baf0428750fa5d6be9c1a36204612a5a33ad5b0d5f8c/pyschematron-1.1.3.tar.gz",
    "platform": null,
    "description": "############\nPySchematron\n############\nThis is a library package for Schematron validation in Python.\n\nSchematron is a schema language used to validate XML documents.\nA Schematron schema is defined as an XML containing various assertions to validate a target XML document.\nIf the XML you wish to validate passes all the Schematron assertions,\nyour XML is considered valid according to the Schematron schema.\nComplete validation results are offered using the Schematron Validation Report Language,\na loose definition of an XML based validation report.\n\nThere are various versions of Schematron available.\nThis library only supports the latest version of Schematron,\n`ISO/IEC 19757-3:2020 <https://www.iso.org/standard/74515.html>`_, with a few limitations (see below).\n\nCurrently, this library only supports a pure Python mode of Schematron validation.\nIn this pure Python mode we load the Schematron into an internal representation and apply that to an XML.\nThe advantage of such direct evaluation is that it offers superior performance compared to an XSLT\ntransformation based evaluation.\nThe disadvantage is that it only supports XPath expressions and does not support XSLT functions.\n\nIn the future we hope to expand this library with an XSLT transformation based processing.\nUnfortunately XSLT transformations require an XSLT processor,\nwhich is currently not available in Python for XSLT >= 2.0.\n\nA few similar packages to this software in other languages are\n`node-schematron <https://github.com/wvbe/node-schematron#readme>`_ in Javascript, and\n`ph-schematron <http://phax.github.io/ph-schematron/>`_ in Java.\n\nFor all XPath expressions this package uses the\n`elementpath <https://github.com/sissaschool/elementpath>`_ library supporting XPath 1.0, 2.0, 3.0 and 3.1 selectors.\n\nPlease note that, as of this writing, this package only supports Python 3.12.\nOlder Python versions are not supported due to missing functionality (Python syntax primarily).\nNewer versions will be supported in due time.\n\n**********\nPython API\n**********\nTo use the Python API, install the project like any other Python project, e.g. using ``pip install pyschematron``.\n\nAfter that you can use:\n\n.. code:: python\n\n    from pyschematron import validate_document\n\n    result = validate_document(<xml_document.xml>, <schematron_schema.sch>)\n\n    svrl = result.get_svrl()\n    is_valid = result.is_valid()\n\n\nTo process multiple documents with the same Schematron schema, you can use:\n\n.. code:: python\n\n    from pyschematron import validate_document\n\n    documents = [...]\n    schema = <schema.sch>\n\n    results = validate_documents(documents, schema)\n\n\nFor more examples, or examples on how to use different parts of the API, please see the `demo_*` files in the\n`scripts` directory.\n\n\n**********************\nCommand Line Interface\n**********************\nTo use the command line interface, first install the application using pip: ``pip install pyschematron``.\nAfterwards, you can use the command ``pyschematron`` to validate your documents.\nUse ``pyschematron --help`` to see the command line options.\n\n\n*************\nFunctionality\n*************\nThis library offers a basic implementation of Schematron using a pure Python \"direct mode\" evaluation method.\n\nDirect mode evaluation\n======================\nThe direct mode evaluation allows for basic validity checks using all XPath functionality of Schematron.\n\nWhen applied to a document, the direct mode evaluation follows this procedure to validate a document:\n\n#. Read in the Schematron from either a document or a string.\n   In this phase the document is loaded into an AST (abstract syntax tree).\n   All ``<includes />`` are resolved and inlined into the AST.\n   All ``<extends />`` are loaded but not fully resolved at this stage.\n#. Recreate the AST without abstract patterns and rules.\n   In this phase we process the AST to create a concrete set of patterns and rules.\n   All ``<extends />`` are resolved, abstract patterns are instantiated,\n   and redundant abstract rules and patterns are removed.\n#. Phase selection, we limit the AST to only include patterns and phases limited to the selected phase.\n#. Query binding, we determine the query binding language to use.\n   This library only supports ``xslt``, ``xslt2``, ``xslt3``, ``xpath``, ``xpath2``, ``xpath3``, and ``xpath31``,\n   where all ``xslt`` variations are limited to XPath expressions only.\n#. Apply the bound schema to an XML document to validate.\n\n\nCustom functions\n----------------\nWith the current direct mode evaluation method, custom XSLT functions in your Schematron (``<xsl:function>``) are not supported.\nCustom Python functions are supported however. View the `demo_custom_functions.py` in the `scripts` directory for examples.\n\n\nCompliance\n----------\nThe direct mode evaluation supports most of the `ISO/IEC 19757-3:2020 <https://www.iso.org/standard/74515.html>`_ standard, with a few exceptions.\nAll Schematron specific elements are supported, except for XSLT elements.\n\nIn terms of attributes, the ``@documents`` attribute of the ``<assert />`` tag is not supported.\nFurthermore, ``@icon``, ``@see``, ``@fpi``, ``@flag``, and ``@role`` are loaded but not used.\n\nNote that the ISO Schematron applies rules to:\n\n- Elements (*)\n- Attributes (@*)\n- Root node (/)\n- Comments (comment())\n- Processing instructions (processing-instruction())\n\nBut it does not apply rules to text nodes.\n\nIf there are any problems, please open a Github issue.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Schematron validation in Python.",
    "version": "1.1.3",
    "project_urls": null,
    "split_keywords": [
        "schematron",
        " xml validation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "de2e07a0b23a4fbda49cad7f37d84f63aa0a0364e64b43e2e4aa996d278ff65a",
                "md5": "9e7ce8d31d937a59d46bbe414a385e5d",
                "sha256": "46b2502958ea92599c7e3644a3d677d4cf7586d8b776f528c5b148d346b97a7f"
            },
            "downloads": -1,
            "filename": "pyschematron-1.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9e7ce8d31d937a59d46bbe414a385e5d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 71140,
            "upload_time": "2024-12-21T12:29:28",
            "upload_time_iso_8601": "2024-12-21T12:29:28.636785Z",
            "url": "https://files.pythonhosted.org/packages/de/2e/07a0b23a4fbda49cad7f37d84f63aa0a0364e64b43e2e4aa996d278ff65a/pyschematron-1.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cf0a9d597427e75e5dd0baf0428750fa5d6be9c1a36204612a5a33ad5b0d5f8c",
                "md5": "4356077a9030baa6855f65c53ca650ee",
                "sha256": "05f6ab92c6976a6969cd6f8711cb73633854cba511523c945f1f01ddc3ffc29f"
            },
            "downloads": -1,
            "filename": "pyschematron-1.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "4356077a9030baa6855f65c53ca650ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 491216,
            "upload_time": "2024-12-21T12:29:30",
            "upload_time_iso_8601": "2024-12-21T12:29:30.868217Z",
            "url": "https://files.pythonhosted.org/packages/cf/0a/9d597427e75e5dd0baf0428750fa5d6be9c1a36204612a5a33ad5b0d5f8c/pyschematron-1.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 12:29:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyschematron"
}
        
Elapsed time: 0.41367s