PyShEx
Python ShEx interpreter
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 pyshexuv
uv add pyshexpoetry
poetry add pyshexInstalling 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
Tags
More Compilers packages
pyparsing provides a library for building text…
permissive · top 1,000 on PyPI
CythonCython is a source code translator that…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
numbaNumba is a just-in-time compiler that…
permissive · top 1,000 on PyPI
tree-sitterPython bindings to the tree-sitter parsing…
permissive · top 1,000 on PyPI
llvmlitellvmlite provides a lightweight Python binding…
permissive · top 1,000 on PyPI
PyShexCParses Shape Expression Compact (ShExC) syntax…
permissive · top 15,000 on PyPI
ShExJSGShExJSG provides a Python object model for the…
permissive · top 15,000 on PyPI
rdflibRDFLib is a Python library for parsing,…
permissive · top 1,000 on PyPI
pyshaclValidates RDF graphs against SHACL shape…
permissive · top 5,000 on PyPI
CFGraphCFGraph extends rdflib's Graph to read RDF…
permissive · top 15,000 on PyPI
linkmlLinkML is a modeling language for defining…
permissive · top 15,000 on PyPI
pymanticPymantic parses and queries RDF and semantic…
permissive · top 15,000 on PyPI
owlrlImplements OWL2 RL Profile and RDFS inference…
unclear · top 5,000 on PyPI
pyrdfa3Parses RDFa markup embedded in HTML documents…
unclear · top 15,000 on PyPI
sssomParse, validate, and convert SSSOM (Simple…
permissive · top 15,000 on PyPI