This repository was originally developed by Eric Prud'hommeaux (@ericprud). All credit goes to him and other original developers. The reason for creating a detached fork (original repo) in the LinkML organization was to be able to support Python 3.14 in LinkML and to put the project in an organization that would allow for sustainability through community exposure as the library did not receive updates in the last years. Efforts to get in touch with the original developers sadly was not successful.
PyShExC - The Python ShExC Parser
This package converts the Shape Expression Compact (ShExC) into Python JSON Schema Binding (pyjsg) objects. The pyjsg object representation can be used to:
- Produce equivalent ShEx definitions in ShEx JSON (ShExJ) notation
- Produce equivalent ShEx definitions in ShEx RDF (ShExR) notation
- Implement a Python ShEx interpreter
History
- 0.4.0 -- Almost ready for 2.1 release. 9 test errors remain, all involving unicode
- 0.4.1 -- Added contextcache. See test_shexr for how to use
- 0.4.2 -- Tweaks in 4 and 8 byte unicode parsing
- 0.5.0 -- Passes all 2.1 tests
- 0.5.1 -- Fix requirements
- 0.5.2 -- Add URL fetch ability and fix UTF8-BOM issue
- 0.5.3 -- Factor out fetch ability for re-use in other packages
- 0.5.4 -- Fix to 0.5.2 -- low probability type matches have to be ignored
- 0.10.0 -- Support for Python 3.10-3.14. Change of build.
- 0.10.1 -- Updated release workflow.
Installation
> pip install PyShExC
Usage
Command Line
usage: shexc_to_shexj [-h] [-nj] [-nr] [-j JSONFILE] [-r RDFFILE]
[--context CONTEXT]
[-f {trix,trig,ttl,n3,turtle,ntriples,xml,json-ld,nt11,pretty-xml,nquads,nt}]
infile
positional arguments:
infile Input ShExC specification
optional arguments:
-h, --help show this help message and exit
-nj, --nojson Do not produce json output
-nr, --nordf Do not produce rdf output
-j JSONFILE, --jsonfile JSONFILE
Output ShExJ file (Default: {infile}.json)
-r RDFFILE, --rdffile RDFFILE
Output ShExR file (Default: {infile}.{fmt suffix})
--context CONTEXT Alternative @context for json to RDF
-f {trix,trig,ttl,n3,turtle,ntriples,xml,json-ld,nt11,pretty-xml,nquads,nt}, --format {trix,trig,ttl,n3,turtle,ntriples,xml,json-ld,nt11,pretty-xml,nquads,nt}
Output format (Default: turtle)
> wget https://raw.githubusercontent.com/shexSpec/shexTest/master/schemas/FocusIRI2groupBnodeNested2groupIRIRef.shex -O test.shex
> shexc_to_shexj test.shex --context shex.jsonld
JSON output written to test.json
turtle output written to test.ttl
test.shex
<http://a.example/S1> IRI /^https?:\/\// {
<http://a.example/p1> <http://a.example/dt1> ;
<http://a.example/p2> BNODE {
<http://a.example/p3> LITERAL ;
<http://a.example/p4> IRI /^https?:\/\// @<http://a.example/S1>?
} AND CLOSED { <http://a.example/p3> . ; <http://a.example/p4> . }
}
test.json
{
"type": "Schema",
"@context": "http://www.w3.org/ns/shex.jsonld",
"shapes": [
{
"type": "ShapeAnd",
"id": "http://a.example/S1",
"shapeExprs": [
{
"type": "NodeConstraint",
"nodeKind": "iri",
"pattern": "^https?://"
},
{
"type": "Shape",
"expression": {
"type": "EachOf",
"expressions": [
{
"type": "TripleConstraint",
"predicate": "http://a.example/p1",
"valueExpr": {
"type": "NodeConstraint",
"datatype": "http://a.example/dt1"
}
},
{
"type": "TripleConstraint",
"predicate": "http://a.example/p2",
"valueExpr": {
"type": "ShapeAnd",
"shapeExprs": [
{
"type": "ShapeAnd",
"shapeExprs": [
{
"type": "NodeConstraint",
"nodeKind": "bnode"
},
{
"type": "Shape",
"expression": {
"type": "EachOf",
"expressions": [
{
"type": "TripleConstraint",
"predicate": "http://a.example/p3",
"valueExpr": {
"type": "NodeConstraint",
"nodeKind": "literal"
}
},
{
"type": "TripleConstraint",
"predicate": "http://a.example/p4",
"valueExpr": {
"type": "ShapeAnd",
"shapeExprs": [
{
"type": "NodeConstraint",
"nodeKind": "iri",
"pattern": "^https?://"
},
"http://a.example/S1"
]
},
"min": 0,
"max": 1
}
]
}
}
]
},
{
"type": "Shape",
"closed": "true",
"expression": {
"type": "EachOf",
"expressions": [
{
"type": "TripleConstraint",
"predicate": "http://a.example/p3"
},
{
"type": "TripleConstraint",
"predicate": "http://a.example/p4"
}
]
}
}
]
}
}
]
}
}
]
}
]
}
test.ttl
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix shex: <http://www.w3.org/ns/shex#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://a.example/S1> a shex:ShapeAnd ;
shex:shapeExprs ( [ a shex:NodeConstraint ;
shex:nodeKind shex:iri ;
shex:pattern "^https?://" ] [ a shex:Shape ;
shex:expression [ a shex:EachOf ;
shex:expressions ( [ a shex:TripleConstraint ;
shex:predicate <http://a.example/p1> ;
shex:valueExpr [ a shex:NodeConstraint ;
shex:datatype <http://a.example/dt1> ] ] [ a shex:TripleConstraint ;
shex:predicate <http://a.example/p2> ;
shex:valueExpr [ a shex:ShapeAnd ;
shex:shapeExprs ( [ a shex:ShapeAnd ;
shex:shapeExprs ( [ a shex:NodeConstraint ;
shex:nodeKind shex:bnode ] [ a shex:Shape ;
shex:expression [ a shex:EachOf ;
shex:expressions ( [ a shex:TripleConstraint ;
shex:predicate <http://a.example/p3> ;
shex:valueExpr [ a shex:NodeConstraint ;
shex:nodeKind shex:literal ] ] [ a shex:TripleConstraint ;
shex:max 1 ;
shex:min 0 ;
shex:predicate <http://a.example/p4> ;
shex:valueExpr [ a shex:ShapeAnd ;
shex:shapeExprs ( [ a shex:NodeConstraint ;
shex:nodeKind shex:iri ;
shex:pattern "^https?://" ] <http://a.example/S1> ) ] ] ) ] ] ) ] [ a shex:Shape ;
shex:closed true ;
shex:expression [ a shex:EachOf ;
shex:expressions ( [ a shex:TripleConstraint ;
shex:predicate <http://a.example/p3> ] [ a shex:TripleConstraint ;
shex:predicate <http://a.example/p4> ] ) ] ] ) ] ] ) ] ] ) .
[] a shex:Schema ;
shex:shapes <http://a.example/S1> .
Release files for PyShexC 0.10.3.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyshexc-0.10.3.post1.tar.gz | 130.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyshexc-0.10.3.post1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 201.7 kB
Release files / pyshexc-0.10.3.post1.tar.gz
| Download URL | pyshexc-0.10.3.post1.tar.gz |
|---|---|
| Size | 130.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80d9d067c80af9a796e3c1c47d2207edf2e9a9fc39d3ca0ce5dd2019334ea915
|
|
BLAKE2b-256 checksum How to use checksums |
36c581196cd2ab23953c4a8d39c7627437984bf8566eae896c5745356a7de7c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency logRelease files / pyshexc-0.10.3.post1-py3-none-any.whl
| Download URL | pyshexc-0.10.3.post1-py3-none-any.whl |
|---|---|
| Size | 71.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d247f2822ef9864152545935d93a07dce66640608ea9414c96f69da7fe7a168
|
|
BLAKE2b-256 checksum How to use checksums |
5e1dd8d5be9e72e518b42f544e196de9c07161b0933143c9d0e4e2e33de60d79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 1, 2026.
Transparency log