skillfed

PyShEx

Python ShEx interpreter

pyshex v0.9.0 302.6K downloads/30d#7,820 on PyPI
Permissive license CC0 1.0 Universal Active released

What it is and what it does

PyShEx is a Python implementation of the Shape Expressions Language 2.0 specification, allowing you to parse ShEx schemas (in both ShExC and ShExJ formats) and validate RDF graphs against them. It determines whether RDF nodes and their properties conform to the structural and type constraints defined in a ShEx schema, supporting features like SPARQL-based focus node selection, RDF Collections flattening, and detailed validation reporting.

The package wraps the formal ShEx specification closely in Python code, translating semantic rules directly into executable logic. It includes a command-line tool (shexeval) for batch validation and integrates with rdflib for RDF parsing and SPARQL endpoints. The package depends on ShExJSG for AST representation, pyshexc for ShExC parsing, and several RDF utilities (rdflib-shim, sparqlwrapper, sparqlslurper) to handle diverse RDF sources and query patterns.

Use it for:

  • Validate RDF data against organizational or domain-specific shape constraints before ingesting into a knowledge graph.
  • Test RDF export pipelines to ensure generated triples conform to expected structural schemas.
  • Query SPARQL endpoints and validate the results against ShEx schemas in a single workflow.
  • Batch-validate large RDF files or multiple datasets using the shexeval CLI with focus node selection by type or predicate.
  • Integrate shape validation into linked data publishing pipelines to catch schema violations early.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

PyShEx parses and validates RDF data against Shape Expressions (ShEx) schemas, implementing the ShEx 2.0 specification to check whether RDF graphs conform to defined structural constraints.

Yes, with conditions. Install if you need to validate RDF against ShEx schemas and can tolerate that some unit tests are failing due to a long maintenance gap. The package is actively maintained now and supports current Python versions (3.10–3.14), but review the open issues and test manifest before relying on complex or edge-case validation logic. No known security vulnerabilities.

Install

pyshex on PyPI

pip

pip install pyshex

uv

uv add pyshex

poetry

poetry add pyshex

Installing PyShEx

Before you install

Low install friction with a pure-Python wheel. Maintenance is active but the package carries a caveat: the current release was issued to support Python 3.14 after a long development hiatus, and some unit tests remain failing due to outdated code or genuine bugs—consult issues before relying on edge cases.

License in practice

Licensed under CC0 1.0 Universal (public domain dedication), placing no restrictions on use, modification, or distribution for any purpose.

Quickstart

pip install PyShEx

from pyshex.shex_evaluator import ShExEvaluator

evaluator = ShExEvaluator(rdf='data.ttl', shex='schema.shex')
result = evaluator.evaluate()

Requires Python 3.10 or later. If using JSON-LD parsing, note that rdflib-jsonld is incompatible with the bleeding-edge rdflib version needed for single-quote escaping in RDF literals.

Verify before relying

  • Whether all 81 skipped tests in the official test suite (52 bnode identity, 18 ShEx 2.1 IMPORT, 3 shapemap, 2 relative IRI, 6 rdflib quote escaping) affect real-world use cases.
  • Current status of the rdflib single-quote escaping issue and whether a workaround is available without using bleeding-edge rdflib.
  • Which specific unit tests are failing and whether they impact the validation semantics or only edge cases.

Package facts

License CC0 1.0 Universal (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 9 — cfgraph, chardet, pyshexc, rdflib-shim, requests, shexjsg, sparqlslurper, sparqlwrapper, urllib3
Maintenance actively maintained — 99 days since the last release
First released
Downloads 302,591/month — #7,820 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pyshex-0.9.0-py3-none-any.whl

Keywords: ShEx, rdf

Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: CC0 1.0 Universal (CC0 1.0) Public Domain DedicationProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Compilers

Tags

ShEx validation RDFshape expressions interpreterRDF schema validationShEx parser PythonRDF graph validationShEx 2.0 implementationsemantic web validation
rdf-validationsemantic-webschema-validation

More Compilers packages