Python SHACL Validator
Project description
pySHACL
A Python validator for SHACL.
This is a pure Python module which allows for the validation of RDF graphs against Shapes Constraint Language (SHACL) graphs. This module uses the rdflib Python library for working with RDF and is dependent on the OWL-RL Python module for OWL2 RL Profile-based expansion of data graphs.
This module is developed to adhere to the SHACL Recommendation:
Holger Knublauch; Dimitris Kontokostas. Shapes Constraint Language (SHACL). 20 July 2017. W3C Recommendation. URL: https://www.w3.org/TR/shacl/ ED: https://w3c.github.io/data-shapes/shacl/
Installation
Install with PIP (Using the Python3 pip installer pip3
)
$ pip3 install pyshacl
Or in a python virtualenv (these example commandline instructions are for a Linux/Unix based OS)
$ python3 -m virtualenv --python=python3 --no-site-packages shaclvenv
$ source ./shaclvenv/bin/activate
$ pip3 install pyshacl
To exit the virtual enviornment:
$ deactivate
Command Line Use
For command line use:
(these example commandline instructions are for a Linux/Unix based OS)
pyshacl -s /path/to/shapesGraph.ttl -m -i rdfs -f human /path/to/dataGraph.ttl
Where
-s
is an (optional) path to the shapes graph to use-i
is the pre-inferencing option-f
is the ValidationReport output format (human
= human-readable validation report)-m
enable the meta-shacl feature
System exit codes are:
0
= DataGraph is Conformant
1
= DataGraph is Non-Conformant
2
= The validator encountered a RuntimeError (check stderr output for details)
3
= Not-Implemented; The validator encountered a SHACL feature that is not yet implemented.
Full CLI Usage options:
pyshacl [-h] [-s [SHACL]] [-i {none,rdfs,owlrl,both}] [-m] [-a] [-d]
[-f {human,turtle,xml,json-ld,nt}] [-o [OUTPUT]]
DataGraph
positional arguments:
DataGraph The file containing the Target Data Graph.
optional arguments:
-h, --help show this help message and exit
-s [SHACL], --shacl [SHACL]
[Optional] The file containing the SHACL Shapes Graph.
-i {none,rdfs,owlrl,both}, --inference {none,rdfs,owlrl,both}
[Optional] Choose a type of inferencing to run against
the Data Graph before validating.
-m, --metashacl [Optional] Validate the SHACL Shapes graph against the
shacl-shacl Shapes Graph before before validating the
Data Graph.
-a, --abort [Optional] Abort on first error.
-d, --debug [Optional] Output additional runtime messages.
-f {human,turtle,xml,json-ld,nt}, --format {human,turtle,xml,json-ld,nt}
[Optional] Choose an output format. Default is
"human".
-o [OUTPUT], --output [OUTPUT]
[Optional] Send output to a file (defaults to stdout).
Python Module Use
For basic use of this module, you can just call the validate
function of the pyshacl
module like this:
from pyshacl import validate
r = validate(target_graph, shacl_graph, inference='rdfs', abort_on_error=False, meta_shacl=False, debug=False)
conforms, results_graph, results_text = r
where:
target_graph
is an rdflibGraph
object, the graph to be validatedshacl_graph
is an rdflibGraph
object, the graph containing the SHACL shapes to validate with, or None if the SHACL shapes are included in the target_graph.inference
is a Python string value to indicate whether or not to perform OWL inferencing expansion of thetarget_graph
before validation. Options are 'rdfs', 'owlrl', 'both', or 'none'. The default is 'none'.abort_on_error
(optional) a Pythonbool
value to indicate whether or not the program should abort after encountering a validation error or to continue. Default is to continue.meta_shacl
(optional) a Pythonbool
value to indicate whether or not the program should enable the Meta-SHACL feature. Default is False.debug
(optional) a Pythonbool
value to indicate whether or not the program should emit debugging output text. Default is False.
on return:
- a three-component
tuple
containing:conforms
abool
, indicating whether or not thetarget_graph
conforms to theshacl_graph
results_graph
an rdflibGraph
object built according to the SHACL specification's Validation Report semanticsresults_text
python string representing a verbose textual representation of the Validation Report
PySHACL is a Python3 library. For best compatibility use Python v3.5 or greater. This library does not work on Python 2.7.x or below.
Features
A features matrix is kept in the FEATURES file.
Changelog
A comprehensive changelog is kept in the CHANGELOG file.
Benchmarks
This project includes a script to measure the difference in performance of validating the same source graph that has been inferenced using each of the four different inferencing options. Run it on your computer to see how fast the validator operates for you.
License
This repository is licensed under Apache License, Version 2.0. See the LICENSE deed for details.
Contributors
See the CONTRIBUTORS file.
Contacts
Project Lead:
Nicholas Car
Senior Experimental Scientist
CSIRO Land & Water, Environmental Informatics Group
Brisbane, Qld, Australia
nicholas.car@csiro.au
http://orcid.org/0000-0002-8742-7730
Lead Developer:
Ashley Sommer
Software Engineer
CSIRO Land & Water, Environmental Informatics Group
Brisbane, Qld, Australia
Ashley.Sommer@csiro.au
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyshacl-0.9.4.post1.tar.gz
.
File metadata
- Download URL: pyshacl-0.9.4.post1.tar.gz
- Upload date:
- Size: 65.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9f59c58622c7a719af302dbca91fce157df2d620d57e19bff6874fe97d71a9d |
|
MD5 | 2e630fe00ce184c8552ccb09d53bec56 |
|
BLAKE2b-256 | 483a1f2eeaaf564b739aac056b2a6ef4b295e22c69049162401a8a18bcdacc12 |
File details
Details for the file pyshacl-0.9.4.post1-py3-none-any.whl
.
File metadata
- Download URL: pyshacl-0.9.4.post1-py3-none-any.whl
- Upload date:
- Size: 63.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 089ff2924ca5157b010814dba09fbeb5c832b9e27a06240b6957578f93650b17 |
|
MD5 | e3407e6332f029c7d4db84ad2c85b957 |
|
BLAKE2b-256 | 4ea95848c59f54e84321207904a28682c0ed1615b2029f3dbaf61863c1a24bcb |