A compatibility adapter for rdflib version 6.0.
The rdflib 5.x to 6.x transition introduced a couple of breaking changes. This shim makes those changes transparent to the outside world.
In rdflib 5.x, Graph.serialize returned a byte array. This was changed to a str
in rdflib 6.x, which breaks all the code written in the form:
g.serialize(format=...).decode()
This shim decorates the return string from version 6 so that it has an identity decode() method
rdflib_shim adds a wrapper on the rdflib Graph.serialize method that always has a decode() function, whether the
output is in bytes or as a string
rdflib-jsonld was a separate package in the rdflib 5 ecosystem. While it is no longer necessary in
rdflib 6, there is no real harm in still having it present. The issue, however, is as follows:
0.5.0 had a dependency on a variable (no_2to3) in rdflib. This
variable was remove in rdflib 6.0.6.1 works with either rdflib 5 or rdflib 60.6.2 was “tombstoned”, which, in this context means that
pip install rdflib-jsonld and pip install rdflib-jsonld~=0.5 are no-ops. They don’t do anythingfrom rdflib import Graph, RDF, RDFS
import rdflib_shim
# Make sure the import above works
shimed = rdflib_shim.RDFLIB_SHIM
g = Graph()
g.add( (RDFS.Resource, RDF.type, RDFS.resource))
# serialize() and serialize().decode() works in both 5 and 6
g.serialize(format="turtle")
g.serialize(format="turtle").decode()