Redland

Dave Beckett

 
 
Hosted by
Dreamhost

since 2005.

Data

DOAP
(See DOAP Project)

Redland librdf Language Bindings - Python Interface

Installing the Redland Python interface

This is built if --with-python is given to the configure line, or --with-python=python2.3 to use a particular python version/program. The standard 'make' at the top level will build it.

You can also compile the python interface by hand as follows:

  cd python
  make

  # optional - runs the pyunit tests
  make check

To install it system wide do this as root (or maybe via sudo make install):

  root# make install

If you do not want it installed system wide, or do not have write access to the system python area, you can install into any directory you like by setting the DESTDIR as follows:

  $ make install DESTDIR=/path/to/wherever

although you will likely need let python know about this area either by the PYTHONPATH environment variable or some other mechanism. The shared library that provides the interface Redland.so (or similar name) will also be installed and the system will not find it unless that directory is pointed at. This is system specific but the choices are setting environment variables DYLD_LIBRARY_PATH (OSX), LD_LIBRARY_PATH (everyone else) or editing the /etc/ld.so.conf file (Linux, others?). See your system documentation or manual pages about shared library linking such as ld.so(1).

The python interface for Redland is mature and requires Python 2.3 (preferred) or 2.2. It has been tested with the following versions:

2.3.3 on Linux/x86
2.3.3 on FreeBSD/x86
2.3 on OSX/PPC
2.2 on Linux/x86

Testing the Redland Python interface

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

  python example.py

(Using the same chosen earlier)

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.3 python example.py

and the result should be:

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

Using the Redland Python API

Read the pydoc Redland Python API for full details of the classes and methods provided along with examples of use.

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
Querylibrdf_queryRDF.Query Querying of an Model delivering a QueryResults
QueryResultslibrdf_query_resultsRDF.QueryResults Results of applying an Query to a Model giving either variable bindings with Node values or Stream of Statements
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