shacl (Python)
Python bindings for the SHACL validation engine, built with PyO3 and maturin.
Building
pip install maturin
cd crates/shacl-python
maturin develop --release # build and install into the current venv
maturin build --release # produce a wheel in target/wheels
The extension targets the stable ABI (abi3-py39), so one wheel serves every
CPython from 3.9 upwards.
Usage
import shacl
# Compile once, validate many: shapes are fixed while data changes, and
# compiling is a meaningful share of a small run.
shapes = shacl.Shapes.from_file("shapes.ttl")
report = shapes.validate_file("data.ttl")
if not report.conforms:
for r in report.results:
print(r.severity, r.component, r.focus_node, r.value)
Report is truthy when the data conforms and len() gives the result count, so
the common case reads plainly:
if shapes.validate_file("data.ttl"):
print("ok")
For a one-off, or for a self-describing document that carries its own shapes:
shacl.validate("data.ttl") # shapes come from the data graph
shacl.validate("data.ttl", "shapes.ttl")
Turtle can also be passed directly, which is convenient for tests:
shapes = shacl.Shapes.from_turtle(shapes_text)
report = shapes.validate_turtle(data_text)
Notes
Terms are returned as strings in N-Triples syntax — <http://ex/a>,
"42"^^<http://www.w3.org/2001/XMLSchema#integer> — rather than as objects.
That keeps the binding free of a dependency on any particular Python RDF
library; parse them with whichever one you already use.
Threading
A Shapes object is immutable and safe to share. Validation releases the GIL
and clones the term store per run rather than locking a shared one, so
concurrent callers do not serialise on each other.
Measured on stock CPython 3.14 with the GIL enabled — 16 validations of a
69k-triple graph through one shared Shapes:
| threads | throughput |
|---|---|
| 1 | 7.8 runs/s |
| 4 | 26.9 runs/s |
| 8 | 27.8 runs/s |
It plateaus at four because each validation already parses across threads internally, so the cores are busy either way.
Free-threaded builds
The module declares gil_used = false, so it will not force the GIL back on
when imported into a free-threaded interpreter (python3.14t). Note that
free-threading is a separate build, not something a version number brings: a
stock 3.14 still reports sys._is_gil_enabled() == True.
There is little to gain from it here. The GIL is already released around the
work, which is why the table above scales. Free-threading would only help code
doing significant Python-level work in parallel as well — and it costs the
single abi3 wheel, since abi3 is a no-op on free-threaded builds and PyO3
falls back to a version-specific one.
The report as RDF
SHACL defines the validation report as a graph — a sh:ValidationReport — not
as a list of strings. The attributes above are a convenience for reading it from
Python; serialize is what to hand to another RDF tool.
print(shapes.validate_file("data.ttl").serialize())
_:r0 a sh:ValidationReport ;
sh:conforms false ;
sh:result _:r1 .
_:r1 a sh:ValidationResult ;
sh:focusNode <http://ex/a> ;
sh:resultPath <http://ex/age> ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:DatatypeConstraintComponent ;
sh:value "old" .
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shacl-0.1.3.tar.gz.
File metadata
- Download URL: shacl-0.1.3.tar.gz
- Upload date:
- Size: 127.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9f3d6e13bdadc7125c2c96c0695c8f8f193a32eed8f7d9c2b4429bc8ce8f5d6
|
|
| MD5 |
c5edf7c999905c4ccf4196503d09387a
|
|
| BLAKE2b-256 |
3b84e13220f9b424822ceffbad772351091ecffd54222a5f85bf26afb17ca826
|
Provenance
The following attestation bundles were made for shacl-0.1.3.tar.gz:
Publisher:
release.yml on pwin/SHACL_Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shacl-0.1.3.tar.gz -
Subject digest:
b9f3d6e13bdadc7125c2c96c0695c8f8f193a32eed8f7d9c2b4429bc8ce8f5d6 - Sigstore transparency entry: 2417831108
- Sigstore integration time:
-
Permalink:
pwin/SHACL_Engine@473640baa29b8eed08326fa727628772689855d2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/pwin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@473640baa29b8eed08326fa727628772689855d2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file shacl-0.1.3-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: shacl-0.1.3-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd083d806f27730d9dca8336c40d71b8679f53995b8d92c5803fd005b84ecbde
|
|
| MD5 |
64d31d7dd2a90a541ffbc076ed231b9b
|
|
| BLAKE2b-256 |
672c78d67096bc3499f845395e157993735e14f66496c3c79416227387108a1d
|
Provenance
The following attestation bundles were made for shacl-0.1.3-cp39-abi3-win_amd64.whl:
Publisher:
release.yml on pwin/SHACL_Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shacl-0.1.3-cp39-abi3-win_amd64.whl -
Subject digest:
dd083d806f27730d9dca8336c40d71b8679f53995b8d92c5803fd005b84ecbde - Sigstore transparency entry: 2417833707
- Sigstore integration time:
-
Permalink:
pwin/SHACL_Engine@473640baa29b8eed08326fa727628772689855d2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/pwin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@473640baa29b8eed08326fa727628772689855d2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38e2d07fbf21480352de55fbc834be435a91cb20cc3b87bd631d0f20197ca661
|
|
| MD5 |
41ad1257eb444e3b1aab35044647b371
|
|
| BLAKE2b-256 |
46f252238512c09100f2a42319f0645293c89f87a1ee6c2a081c7b17e096a2b6
|
Provenance
The following attestation bundles were made for shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on pwin/SHACL_Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
38e2d07fbf21480352de55fbc834be435a91cb20cc3b87bd631d0f20197ca661 - Sigstore transparency entry: 2417832728
- Sigstore integration time:
-
Permalink:
pwin/SHACL_Engine@473640baa29b8eed08326fa727628772689855d2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/pwin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@473640baa29b8eed08326fa727628772689855d2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.
File metadata
- Download URL: shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.9+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59eac16842e90f2517c9ebe2dccd7532ebabd3b9fc015fe2fdb0ade3dbfbca85
|
|
| MD5 |
269eef2e8ce1155a5a4f82aa8227ad34
|
|
| BLAKE2b-256 |
c699b68cca6cfd27fdb0788bf82ffccdf2b5729d46d2f869b4463497de4ab9a3
|
Provenance
The following attestation bundles were made for shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:
Publisher:
release.yml on pwin/SHACL_Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl -
Subject digest:
59eac16842e90f2517c9ebe2dccd7532ebabd3b9fc015fe2fdb0ade3dbfbca85 - Sigstore transparency entry: 2417832064
- Sigstore integration time:
-
Permalink:
pwin/SHACL_Engine@473640baa29b8eed08326fa727628772689855d2 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/pwin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@473640baa29b8eed08326fa727628772689855d2 -
Trigger Event:
workflow_dispatch
-
Statement type: