Registry / serialization / rdflib-shim

rdflib-shim

JSON →
library1.0.3pypypi✓ verified 88d ago

rdflib-shim is a compatibility layer that smooths over breaking changes between rdflib 5 and 6, allowing code written for rdflib 5 to work with rdflib 6 without modification. Version 1.0.3 (latest) requires Python >=3.7. The library is maintained but low-churn (last release 2022).

pip install rdflib-shim
INSTALL
IMPORT
SIG · RDFLIB-SHIM
R
rdflib-shim
serializationpythonv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rdflib_shim
✓ import rdflib_shim
The shim is imported before importing rdflib. No common wrong import reported.

Import the shim first, then use rdflib as usual with rdflib 6.

import rdflib_shim from rdflib import Graph, URIRef, Literal g = Graph() g.parse('http://example.org/test.ttl', format='turtle') for s, p, o in g: print(s, p, o)
Debug
Known issues
gotchaThe shim must be imported before any rdflib imports. If rdflib is imported first, the patching won't apply.
fix
Always put `import rdflib_shim` as the very first import in your module.
affects: all
deprecatedrdflib-shim may not be needed for new projects targeting rdflib 6+ directly. Its primary purpose is to ease migration from rdflib 5.
fix
For new code, consider writing directly against rdflib 6 APIs and skip the shim.
affects: >=1.0.0
Errors
Common errors & fixes
AttributeError: module 'rdflib' has no attribute 'RDF'
In rdflib 6, the RDF namespace is no longer available under rdflib.RDF; it moved to rdflib.namespace.
fix
Add `import rdflib_shim` before `import rdflib` to restore the old behavior.
AttributeError: module 'rdflib' has no attribute 'term'
rdflib 6 changed internal module structure. Some direct references to rdflib.term fail.
fix
Use `from rdflib.term import *` or import the shim first.
ImportError: cannot import name 'BNode' from 'rdflib'
In rdflib 6, BNode is not directly exported from rdflib.__init__; it's in rdflib.term.
fix
Either use `from rdflib.term import BNode` or install/import rdflib-shim.
Upgrade
Version history
1.0.3latest on PyPI · released Dec 21, 2021
Audit
Dependencies
rdflibrequiredCore dependency; shim patches rdflib's public API to restore rdflib 5 behavior.
Agent activity
5 hits · last 30 days
node
4
Resources
rdflib-shim — pip install rdflib-shim · libregistry