rdflib-shim

Pyversions PyPi

rdflib-shim

A compatibility adapter for rdflib version 6.0.

Background

The rdflib 5.x to 6.x transition introduced a couple of breaking changes. This shim makes those changes transparent to the outside world.

1) Serialize().decode()

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

2) rdflib-jsonld

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:

Recommendations

Usage

from 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()