pyTBSHACL
Python wrapper for TopQuadrant's TopBraid SHACL validator.
PySHACL for RDFLib
does not currently implement
some of the advanced SHACL functionality
which is available with TopBraid's command line validator.
pyTBSHACL implements a python wrapper for the TopBraid validator tool
to help simplify integration with python projects
needing that functionality. It is anticipated that this module will
become redundant as adavanced capabilities are progressively added to PySHACL.
Status
Version 0.0.1 (2019-08-21):
Initial complete implementation. Shape files must be in turtle, data files may be in any RDF format supported by RDFLib. Output in turtle, plain text, or json. Tested on OS X only.
Installation
1. Download and install the TopBraid SHACL validator, following guidance at:
https://github.com/TopQuadrant/shacl
Optionally build the validator from source, see "Building the Validator from Source" below.
2. Set the SHACLROOT environment variable to the absolute path to the
bin folder of the TopBraid SHACL validator distribution.
3. pip install -U pyTBSHACL or clone this repo, cd to the folder,
then run: pip install -e .
Example
Following are run from the examples folder.
Valid data:
$ shacl -d data_00a.ttl -s shape_00.ttl
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms true
] .
Invalid data:
$ shacl -d data_00b.ttl -s shape_00.ttl
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:bob ;
sh:resultMessage "Does not have value ex:Mathematics" ;
sh:resultPath ex:field ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:HasValueConstraintComponent ;
sh:sourceShape []
]
] .
Invalid data with text output:
$ shacl -d data_00b.ttl -s shape_00.ttl -of text
Validation Report
Conforms: False
Results (1):
Results for focus node http://example.org/bob:
Path: http://example.org/field
Severity: Violation
Constraint violation in HasValueConstraintComponent
Message: Does not have value ex:Mathematics
Source shape: ub2bL15C48
Valid Dataset with encoding in json-ld:
$ shacl -d data_01a.json -df json-ld -s shape_01.ttl
@prefix : <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms true
] .
Invalid Dataset encoding:
$ shacl -d data_01b.ttl -s shape_01.ttl
@prefix schema: <http://schema.org/> .
@prefix ex: <http://example.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
[ a sh:ValidationReport ;
sh:conforms false ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:dataset2_encoding ;
sh:resultMessage "A schema:contentUrl is required for the encoding property of a Dataset" ;
sh:resultPath schema:contentUrl ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#contentUrlConstraint0>
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode ex:dataset2_encoding ;
sh:resultMessage "Property needs to have at least 1 values, but found 0" ;
sh:resultPath schema:encodingFormat ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#encodingFormatConstraint0>
] ;
sh:result [ a sh:ValidationResult ;
sh:focusNode [] ;
sh:resultMessage "Property needs to have at least 1 values, but found 0" ;
sh:resultPath schema:encodingFormat ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MinCountConstraintComponent ;
sh:sourceShape <http://ns.dataone.org/schema/2019/08/SO/Dataset#encodingFormatConstraint0>
]
] .
Building the Validator from Source
The most recent version of the TopBraid shacl validator can be built from source as follows:
- Clone the repository:
git clone https://github.com/TopQuadrant/shacl
- Build the package:
cd shacl
mvn clean package
- Deploy the built package. The package is a .zip file in the
targetfolder named like ``. Unzip that file to the desired installation location, e.g.:
cd ~/bin
unzip ~/git/shacl/target/shacl-1.x.y-SNAPSHOT-bin.zip
export SHACLROOT="~/git/shacl/target/shacl-1.x.y-SNAPSHOT/bin"
Metadata
Release files for pyTBSHACL 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyTBSHACL-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyTBSHACL-0.0.1-py3-none-any.whl |
Release files / pyTBSHACL-0.0.1-py3-none-any.whl
| Download URL | pyTBSHACL-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bd409bb32d209c69b4c6779eb1aa5b9ffc8619c15446999e2d4e47dbaa85222
|
|
BLAKE2b-256 checksum How to use checksums |
8c08245dfb9dc3b64121a6c7526a315bab961017267f354c979c426634a8eb9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3
|
Security for pyTBSHACL 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.