Registry / data / pyshacl

pyshacl

JSON →
library0.31.0pypypi✓ verified 87d ago

PySHACL is a Python library that implements the W3C Shapes Constraint Language (SHACL) specification. It allows users to validate RDF data graphs against SHACL shapes, identify data quality issues, and generate detailed validation reports. Currently at version 0.31.0, the library maintains an active release cadence, with significant updates and fixes appearing every 1-3 months.

pip install pyshacl
INSTALL
IMPORT
SIG · PYSHACL
P
pyshacl
datapythonv0.31.0
Install
2.8s avg
Import
490ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.31.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.526s · 40.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.8s · import 0.454s · 41MB
37MB installed
● package 37MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validate
from pyshacl import validate

This example demonstrates how to validate a simple RDF data graph against a SHACL shapes graph using `pyshacl.validate`. It defines two in-memory graphs, one containing sample data and another defining a shape that requires every `ex:Person` to have exactly one `ex:name`. The validation identifies `ex:Jane` as non-conformant.

from pyshacl import validate from rdflib import Graph, Literal, URIRef from rdflib.namespace import SH, XSD # Define data graph and shapes graph in TTL format data_graph_ttl = """ @prefix ex: <http://example.com/ns#> . @prefix sh: <http://www.w3.org/ns/shacl#> . ex:John a ex:Person ; ex:name "John Doe" . ex:Jane a ex:Person . # This node will violate ex:PersonShape (missing ex:name) """ shapes_graph_ttl = """ @prefix ex: <http://example.com/ns#> . @prefix sh: <http://www.w3.org/ns/shacl#> . ex:PersonShape a sh:NodeShape ; sh:targetClass ex:Person ; sh:property [ sh:path ex:name ; sh:minCount 1 ; sh:maxCount 1 ; sh:datatype xsd:string ; ] . """ # Load graphs using RDFLib data_graph = Graph().parse(data=data_graph_ttl, format="ttl") shapes_graph = Graph().parse(data=shapes_graph_ttl, format="ttl") # Validate the data graph against the shapes graph conforms, results_graph, results_text = validate( data_graph, shacl_graph=shapes_graph, inference='rdfs', # Perform RDFS inference before validation serialize_report_graph=True # Return the report graph as an RDFLib Graph ) print(f"Validation Conforms: {conforms}") if not conforms: print("\nValidation Report:") print(results_text) # for s, p, o in results_graph.triples((None, SH.resultMessage, None)): # print(f" - {o}")
pyshacl --version
Debug
Known issues
breakingSupport for Python 3.7 and earlier was dropped in PySHACL v0.25.0. Users on older Python versions must upgrade to Python 3.8.1+ or use a PySHACL version less than 0.25.0.
fix
Upgrade Python to 3.8.1 or newer. For existing projects, pin PySHACL to `<0.25.0`.
affects: >=0.25.0
breakingPySHACL v0.25.0 and later only support RDFLib versions 6.3.2 and higher. Older RDFLib versions (e.g., 6.2.0 or earlier) are no longer compatible.
fix
Ensure your RDFLib installation is `rdflib>=6.3.2,<8.0.0` (or the latest compatible version) via `pip install --upgrade rdflib`.
affects: >=0.25.0
gotchaIn PySHACL versions prior to v0.28.1, the library could aggressively overwrite the root Python logger, potentially removing other application-defined handlers. This was fixed in v0.28.1.
fix
Upgrade to PySHACL v0.28.1 or newer to avoid unintended logging side effects. If unable to upgrade, consider configuring your logger *after* PySHACL initialization or using a named logger instead of the root logger.
affects: <0.28.1
breakingStarting with v0.31.0, the default behavior for validating multiple data graphs has changed. Providing multiple data graphs to the `validate` function will now combine them into a single `Dataset` for validation. For independent validation of each graph, use the new `validate_each()` entrypoint or the `--validate-each` CLI flag.
fix
Review existing code that passes multiple data graphs. If independent validation per graph is desired, refactor to use `pyshacl.validate_each()` or loop through graphs calling `pyshacl.validate()` individually. Otherwise, be aware of the new combined dataset behavior.
affects: >=0.31.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyshacl'
The pyshacl library has not been installed in the current Python environment.
fix
pip install pyshacl
ModuleNotFoundError: No module named 'rdflib'
The pyshacl library depends on rdflib, but rdflib is not installed in the current Python environment.
fix
pip install rdflib
rdflib.exceptions.ParserError: Could not deserialize input graph
The provided data graph or shapes graph file contains syntax errors or is not in the expected RDF format, preventing rdflib from parsing it.
fix
Verify the syntax of your RDF file (e.g., Turtle, RDF/XML) and ensure the specified `data_graph_format` or `shacl_graph_format` parameter (or CLI option) matches the actual file format.
pyshacl.errors.ReportableRuntimeError: Failed to load shapes graph
The shapes graph file specified either does not exist, is inaccessible, or contains errors that prevent it from being loaded and parsed as a valid SHACL graph.
fix
Ensure the path to the shapes file is correct and accessible, and that the file contains valid SHACL syntax in the specified RDF format.
Upgrade
Version history
0.31.0latest on PyPI · released Jan 16, 2026
Audit
Dependencies
rdflibrequiredCore dependency for RDF graph manipulation and parsing.
larkrequiredUsed for parsing SHACL syntax.
Agent activity
45 hits · last 30 days
node
44
Resources