Redland - RDF Application Framework - Python Interface

Installing the Redland Python interface

This is not automatically built or installed at present since this interface may not be required. You can easily build it by hand as follows

  cd python
  make build-python
  make test-python   # optional

To install it system wide (this is optional) do this as root:

  root# make install-python

The python interface for Redland 0.9.11+ requires Python 2.2 (it also seems to work with 2.1). Earlier versions of Redland work with previous python versions.

Testing the Redland Python interface

If you did the optional install above, run the python example program with:

  python example.py

Otherwise, to run it in the source tree you need to find out the architecture-specific sub-directory it created in the build directory such as build/lib.linux-i686-2.2 and run it with:

  PYTHONPATH=build/lib.linux-i686-2.2 python example.py

and the result should be:

  found statement: {[http://purl.org/net/dajobe/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"}
  Parsing URI (file) ../perl/dc.rdf
  Parsing added 3 statements
  Printing all statements
  Statement: {[http://purl.org/net/dajobe/], [http://purl.org/dc/elements/1.1/title], "Dave Beckett's Home Page"}
  Statement: {[http://purl.org/net/dajobe/], [http://purl.org/dc/elements/1.1/description], "The generic home page of Dave Beckett."}
  Statement: {[http://purl.org/net/dajobe/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"}
  Statement: {[http://purl.org/net/dajobe/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"}
  Writing model to test-out.rdf as rdf/xml
  Done

Redland Python API Introduction

Read the Redland Python API (Pydoc) for full details of the classes.

The Python API is an object-based API reflecting the same structure of the Redland objects with simple mappings between them:

ConceptRedland ClassPython ClassPurpose
Resource / Literallibrdf_nodeRDF.Node RDF Model & Syntax nodes
Statement / Triplelibrdf_statementRDF.Statement RDF Model & Syntax arcs (statements, triples) [isa Resource]
Modellibrdf_modelRDF.Model Set of Statements usually held in one Storage.
Storagelibrdf_storageRDF.Storage Storage for Models either persistant or in-memory.
Streamlibrdf_streamRDF.Stream Providing sequences of Statements from Parsers, queries.
Parserlibrdf_parserRDF.Parser Syntaxes parsers delivering Stream of Statements or writing to a Model
Serializerlibrdf_serializerRDF.Serializer Serializes a Model into a syntax such as RDF/XML
Iteratorlibrdf_iteratorRDF.Iterator Enumerating lists (of Node) from queries.
URIlibrdf_uriRDF.Uri Provides URIs for Resources, Parsers, ...
World RDF.World RDF wrapper class handling Redland startup/shutdown
Digestlibrdf_digest  Internal content digest class
Hashlibrdf_hash  Internal key:value maps class
Listlibrdf_list  Internal list class

Other RDF Python APIs and applications


Copyright 2000-2002 Dave Beckett, Institute for Learning and Research Technology, University of Bristol