PyShExC - Python ShEx Compiler
raw JSON → 0.9.1 verified Mon Apr 27 auth: no python
PyShExC compiles Shape Expressions (ShEx) schemas into Python executable shapes. Version 0.9.1 supports ShEx 2.1 grammar, requires Python >=3.7, and is released irregularly.
pip install pyshexc Common errors
error ModuleNotFoundError: No module named 'antlr4' ↓
cause Missing runtime dependency antlr4-python3-runtime.
fix
pip install antlr4-python3-runtime
error AttributeError: module 'pyshexc' has no attribute 'compile' ↓
cause Using deprecated import path: from pyshexc import compile.
fix
Use from pyshexc.parser import compile_shex instead.
Warnings
gotcha compile_shex expects a ShEx schema string, not a file path. To read from file, open and read the file yourself. ↓
fix with open('schema.shex') as f: compile_shex(f.read())
deprecated The top-level function 'compile' (from pyshexc) is deprecated; use 'compile_shex' from pyshexc.parser instead. ↓
fix from pyshexc.parser import compile_shex
Imports
- compile_shex wrong
from pyshexc import compile_shexcorrectfrom pyshexc.parser import compile_shex - ShExCVisitor
from pyshexc.parser import ShExCVisitor
Quickstart
from pyshexc.parser import compile_shex
shex_schema = """
PREFIX ex: <http://example.org/>
ex:User IRI {
ex:name xsd:string ;
ex:email xsd:string
}
"""
try:
compiled = compile_shex(shex_schema)
print("Schema compiled successfully")
print(type(compiled))
except Exception as e:
print(f"Compilation error: {e}")