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/

Download files

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

Source Distribution

shacl_sparql_extensions_engine-1.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file shacl_sparql_extensions_engine-1.1.0.tar.gz.

File metadata

File hashes

Hashes for shacl_sparql_extensions_engine-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fdca4e7eea763b0fc23293e48f18f5a15caf3fb125871e0558f0e8ab79aa5334
MD5 17e425783f5bf3029b666925507a0708
BLAKE2b-256 96deea2ccdca24d58426382f5b0a691146037342fcde53f38c4bb55d63b6eec1

See more details on using hashes here.

File details

Details for the file shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shacl_sparql_extensions_engine-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5b935c1eb6f18a978bd018858d7de0956319632b0bfa363ffaa4a4ff754023d
MD5 d0b3b5926e36e7abea43a3172cff62f4
BLAKE2b-256 7b7c269a6ccdeec8e6f058f25c2bc1e5c8fecd53117a88318eed201bf1b9d966

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

Supported by

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