Developer(s) | Daniel Krech |
---|---|
Initial release | June 4, 2002 |
Stable release |
4.2.0 / February 19, 2015
|
Repository | github |
Operating system | Cross-platform |
Type | Library |
License | BSD |
Website | github |
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information. The library contains an RDF/XML parser/serializer that conforms to the RDF/XML Syntax Specification (Revised). The library also contains both in-memory and persistent Graph backends. It is being developed by a number of contributors and was created by Daniel Krech who continues to maintain it.
RDFLib's use of various Python idioms 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. RDFLib graphs emulate container types and are best thought of as a set of 3-item triples:
RDFLib graphs are not sorted containers; they have ordinary set operations, e.g. add to add a triple, and methods that search triples and return them in arbitrary order.
The following RDFLib classes (listed below) model RDF terms in a graph and inherit off a common Identifier class, which extends Python unicode. Instances of these are nodes in an RDF graph.
RDFLib provides mechanisms for managing Namespaces. In particular, there is a Namespace class which takes (as its only argument) the Base URI of the namespace. Fully qualified URIs in the namespace can be constructed by attribute / dictionary access on Namespace instances:
RDFLib graphs also override __iter__ in order to support iteration over the contained triples:
__iadd__ and __isub__ are overridden to support adding and subtracting Graphs to/from each other (in place):
RDFLib graphs support basic triple pattern matching with a triples((subject,predicate,object)) function. This function is a generator of triples that match the pattern given by the arguments. The arguments of these are RDF terms that restrict the triples that are returned. Terms that are None are treated as a wildcard.
Triples can be added in two ways:
Similarly, triples can be removed by a call to remove: remove((subject, predicate, object))