Warning
In preparation. This documentation for rdflib 3.0.0 has not yet been reviewed. Some of the code (esp. the “assorted examples”) has not been updated to reflect the changes and refactoring introduced in rdflib 3.0.0.
A pure Python package providing the core RDF constructs.
The rdflib package is intended to provide core RDF types and interfaces for working with RDF. The package defines a plugin interface for parsers, stores, and serializers that other packages can use to implement parsers, stores, and serializers that will plug into the rdflib package.
The primary interface that rdflib exposes for working with RDF is Graph.
A tiny example:
>>> import rdflib
>>> g = rdflib.Graph()
>>> result = g.parse("http://eikeon.com/foaf.rdf")
>>> print "graph has %s statements." % len(g)
graph has 34 statements.
>>>
>>> for s, p, o in g:
... if (s, p, o) not in g:
... raise Exception("It better be!")
>>> s = g.serialize(format='n3')
The package uses various Python idioms that makes them an appropriate way to introduce it to a Python programmer who hasn’t used it before.
rdflib graphs redefine certain built-in Python methods in order to behave in a predictable way; they emulate container types and are best thought of as a set of 3-item triples:
[
(subject, predicate, object),
(subject1, predicate1, object1),
...
(subjectN, predicateN, objectN)
]
rdflib graphs are not sorted containers; they have ordinary set operations (e.g. add() to add a triple) plus methods that search triples and return them in arbitrary order.
rdflib has epydoc-generated API Documentation