Skip to main content

SHACL + SPARQL engine

pipeline status coverage report Latest Release

The goal of this project is to provide a reference implementation of the SHACL 1.2 SPARQL extension.

Framework

The code uses:

Structure

  • shacl_sparql.validate — typed wrapper around pyshacl.validate().
  • shacl_sparql.conformance — static, non-executing scan of a shapes graph for SHACL 1.2 constructs the default pipeline can't evaluate, plus Appendix A pre-binding lint.
  • shacl_sparql.extensions — opt-in closures for the SHACL 1.2 gaps that neither pyshacl nor rdflib implement natively (§5 result annotations, §6 node expressions, §7 custom functions, §8 layer/runOnce/expectedPredicate, RDF-star sh:tempTriple). Nothing here is wired into validate() automatically; conformance.check() names the construct so you know which extension to reach for.

Hello world

from shacl_sparql.validate import validate

# str sources are treated as file paths/URLs by rdflib; use bytes for inline Turtle.
shapes = b"""
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.com/ns#> .

ex:PersonShape
    a sh:NodeShape ;
    sh:targetClass ex:Person ;
    sh:property [
        sh:path ex:name ;
        sh:minCount 1 ;
    ] .
"""

data = b"""
@prefix ex: <http://example.com/ns#> .

ex:Alice a ex:Person ;
    ex:name "Alice" .

ex:Bob a ex:Person .
"""

outcome = validate(data, shapes)
print(outcome.conforms)  # False — ex:Bob has no ex:name
print(outcome.report_text)

Hello world: SHACL + SPARQL constraint

A sh:sparql constraint runs an arbitrary SPARQL SELECT per focus node — any row it returns is a violation. Here it checks that ex:endDate comes after ex:startDate:

from shacl_sparql.validate import validate

shapes = b"""
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix ex: <http://example.com/ns#> .

ex:EventShape
    a sh:NodeShape ;
    sh:targetClass ex:Event ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "ex:endDate must be after ex:startDate." ;
        sh:select \"\"\"
            PREFIX ex: <http://example.com/ns#>
            SELECT $this
            WHERE {
                $this ex:startDate ?start ;
                      ex:endDate ?end .
                FILTER (?end <= ?start)
            }
        \"\"\" ;
    ] .
"""

data = b"""
@prefix ex: <http://example.com/ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:Conference a ex:Event ;
    ex:startDate "2026-09-01"^^xsd:date ;
    ex:endDate "2026-09-03"^^xsd:date .

ex:Workshop a ex:Event ;
    ex:startDate "2026-10-05"^^xsd:date ;
    ex:endDate "2026-10-01"^^xsd:date .
"""

outcome = validate(data, shapes)
print(outcome.conforms)  # False — ex:Workshop's endDate precedes its startDate
print(outcome.report_text)

Conformance

Every push runs the vendored W3C SHACL 1.2 SPARQL Extensions test suite and publishes the results as an EARL report — the standard machine-readable format for implementation conformance, so results can be aggregated alongside other implementations. Latest report (always up to date with main): w3c-earl-report.ttl.

Specification

Specification reference: https://www.w3.org/TR/shacl12-sparql/

Metadata

Release files for shacl-sparql-extensions-engine 1.1.0

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-sparql-extensions-engine 1.1.0
File Size Uploaded Provenance
shacl_sparql_extensions_engine-1.1.0.tar.gz 16.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for shacl-sparql-extensions-engine 1.1.0
File Interpreter ABI Platform
shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.8 kB

Release files / shacl_sparql_extensions_engine-1.1.0.tar.gz

Download URL shacl_sparql_extensions_engine-1.1.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fdca4e7eea763b0fc23293e48f18f5a15caf3fb125871e0558f0e8ab79aa5334
BLAKE2b-256 checksum
How to use checksums
96deea2ccdca24d58426382f5b0a691146037342fcde53f38c4bb55d63b6eec1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl

Download URL shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5b935c1eb6f18a978bd018858d7de0956319632b0bfa363ffaa4a4ff754023d
BLAKE2b-256 checksum
How to use checksums
7b7c269a6ccdeec8e6f058f25c2bc1e5c8fecd53117a88318eed201bf1b9d966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.7

Security for shacl-sparql-extensions-engine 1.1.0

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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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