# Redland - RDF Application Framework - 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
      make check   # optional, but requires librdf to be installed system wide

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

      root# make install

The python interface for Redland requires Python 2.2 (it also works fine with 2.3).

## 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://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/description], "The generic home page of Dave Beckett."}
      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/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

## Redland Python API Introduction

The pydoc Redland Python API contains full details of the classes and methods provided.

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

Concept | Redland Class | Python Class | Purpose
--- | --- | --- | ---
Resource / Literal | librdf_node | `RDF.Node` | RDF Model & Syntax nodes
Statement / Triple | librdf_statement | `RDF.Statement` | RDF Model & Syntax arcs (statements, triples) [isa Resource]
Model | librdf_model | `RDF.Model` | Set of Statements usually held in one Storage.
Storage | librdf_storage | `RDF.Storage` | Storage for Models either persistant or in-memory.
Stream | librdf_stream | `RDF.Stream` | Providing sequences of Statements from Parsers, queries.
Parser | librdf_parser | `RDF.Parser` | Syntaxes parsers delivering Stream of Statements or writing to a Model
Serializer | librdf_serializer | `RDF.Serializer` | Serializes a Model into a syntax such as RDF/XML
Iterator | librdf_iterator | `RDF.Iterator` | Enumerating lists (of Node) from queries.
URI | librdf_uri | `RDF.Uri` | Provides URIs for Resources, Parsers, ...
World |  | `RDF.World` | RDF wrapper class handling Redland startup/shutdown
Digest | librdf_digest |  | Internal content digest class
Hash | librdf_hash |  | Internal key:value maps class
List | librdf_list |  | Internal list class

## Other RDF Python APIs and applications

- Redfoot - parser, store, viewer, editor, query system framework for RDF with web interface for building peer-to-peer web applications.
- RDFLib.net - a Python library with RDF parser, store and serializer Related to Redfoot which uses it.
- 4Suite - collection of python tools including 4RDF that includes RDF metadata support by Fourthought, Inc.
- W3C Semantic Web Area for Play - lots of tools for RDF and beyond research including the Closed World Machine (CWM) data manipulator, rules processor and query system mostly using the Notation 3 textual RDF syntax

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