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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shacl-0.1.3.tar.gz (127.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

shacl-0.1.3-cp39-abi3-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (4.3 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

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

Hashes for shacl-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b9f3d6e13bdadc7125c2c96c0695c8f8f193a32eed8f7d9c2b4429bc8ce8f5d6
MD5 c5edf7c999905c4ccf4196503d09387a
BLAKE2b-256 3b84e13220f9b424822ceffbad772351091ecffd54222a5f85bf26afb17ca826

See more details on using hashes here.

Provenance

The following attestation bundles were made for shacl-0.1.3.tar.gz:

Publisher: release.yml on pwin/SHACL_Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for shacl-0.1.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dd083d806f27730d9dca8336c40d71b8679f53995b8d92c5803fd005b84ecbde
MD5 64d31d7dd2a90a541ffbc076ed231b9b
BLAKE2b-256 672c78d67096bc3499f845395e157993735e14f66496c3c79416227387108a1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for shacl-0.1.3-cp39-abi3-win_amd64.whl:

Publisher: release.yml on pwin/SHACL_Engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for shacl-0.1.3-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38e2d07fbf21480352de55fbc834be435a91cb20cc3b87bd631d0f20197ca661
MD5 41ad1257eb444e3b1aab35044647b371
BLAKE2b-256 46f252238512c09100f2a42319f0645293c89f87a1ee6c2a081c7b17e096a2b6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

File hashes

Hashes for shacl-0.1.3-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 59eac16842e90f2517c9ebe2dccd7532ebabd3b9fc015fe2fdb0ade3dbfbca85
MD5 269eef2e8ce1155a5a4f82aa8227ad34
BLAKE2b-256 c699b68cca6cfd27fdb0788bf82ffccdf2b5729d46d2f869b4463497de4ab9a3

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page