Skip to main content

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" .

Release files for shacl 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shacl 0.1.5
File Size Uploaded
shacl-0.1.5.tar.gz 136.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for shacl 0.1.5
File Interpreter ABI Platform
shacl-0.1.5-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
shacl-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
shacl-0.1.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.9 abi3 macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 Details

Total release size: 9.0 MB

Release files / shacl-0.1.5.tar.gz

Download URL shacl-0.1.5.tar.gz
Size 136.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5969e0d4023969503cfdda4c680649675abdfb69d4278d355260c07f0d7cf09e
BLAKE2b-256 checksum
How to use checksums
08416ad4aadb66060634de72612fd4bce9bfdef527605ba3a9d4296b0c598aec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / shacl-0.1.5-cp39-abi3-win_amd64.whl

Download URL shacl-0.1.5-cp39-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
54a47ed85867b42a177554e0bb4e3a9c0969f805796c1a3f5f1d3a32edf34459
BLAKE2b-256 checksum
How to use checksums
3945913f9d2b5528181a946f4743d2f12ba8de40cd7dfd79608de1c11a9939e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / shacl-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL shacl-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
618a06e98210fad1762e70837c9ff8fb9555a36201316c1e6f3711382194018b
BLAKE2b-256 checksum
How to use checksums
f4ac01040964b405bd95d8374006dfcd9d9cc89d692d33cd0ed03b2e0ec58489
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release files / shacl-0.1.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL shacl-0.1.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 4.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
95f7169dbe05048fd8d2a11fc9143abd90f9bccccb13d3a65b17c3c07f6e70d1
BLAKE2b-256 checksum
How to use checksums
ffa2ffc032b6e19f0126224284c2471a921dbdcc0585e1586a699c9774f4acd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 13, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.2

4 release files

0.3.1

4 release files

0.3.0

4 release files

0.2.0

4 release files

0.1.10

4 release files

0.1.9

4 release files

0.1.8

4 release files

0.1.6

4 release files

This release

0.1.5 This release

4 release files

0.1.4

4 release files

0.1.3

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page