| 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
| 4 | <head> |
| 5 | <title>Redland RDF Application Framework - Python Interface</title> |
| 6 | </head> |
| 7 | <body> |
| 8 | |
| 9 | <h1>Redland RDF Application Framework - Python Interface</h1> |
| 10 | |
| 11 | <h2>Installing the Redland Python interface</h2> |
| 12 | |
| 13 | <p>This is built if <tt>--with-python</tt> is given to the configure |
| 14 | line, or <tt>--with-python=python2.3</tt> to use a particular python |
| 15 | version/program. The standard 'make' at the top level will build it.</p> |
| 16 | |
| 17 | <p>You can also compile the python interface by hand as follows:</p> |
| 18 | |
| 19 | <pre> |
| 20 | cd python |
| 21 | make |
| 22 | |
| 23 | # optional - runs the pyunit tests |
| 24 | make check |
| 25 | </pre> |
| 26 | |
| 27 | <p>To install it system wide do this as <em>root</em> (or maybe via |
| 28 | sudo make install):</p> |
| 29 | |
| 30 | <pre> |
| 31 | root# make install |
| 32 | </pre> |
| 33 | |
| 34 | <p>If you do not want it installed system wide, or do not have write |
| 35 | access to the system python area, you can install into any directory |
| 36 | you like by setting the <code>DESTDIR</code> as follows:</p> |
| 37 | |
| 38 | <pre> |
| 39 | $ make install DESTDIR=/path/to/wherever |
| 40 | </pre> |
| 41 | |
| 42 | <p>although you will likely need let python know about this area |
| 43 | either by the <code>PYTHONPATH</code> environment variable or some |
| 44 | other mechanism. The shared library that provides the interface |
| 45 | <code>Redland.so</code> (or similar name) will also be installed and |
| 46 | the system will not find it unless that directory is pointed at. |
| 47 | This is system specific but the choices are setting environment |
| 48 | variables <code>DYLD_LIBRARY_PATH</code> (OSX), |
| 49 | <code>LD_LIBRARY_PATH</code> (everyone else) or editing the |
| 50 | <code>/etc/ld.so.conf</code> file (Linux, others?). See your system |
| 51 | documentation or manual pages about shared library linking such as |
| 52 | <code>ld.so(1)</code>. |
| 53 | </p> |
| 54 | |
| 55 | |
| 56 | <p>The python interface for Redland is mature and requires Python 2.3 |
| 57 | (preferred) or 2.2. It has been tested with the following |
| 58 | versions:</p> |
| 59 | |
| 60 | <blockquote> |
| 61 | 2.3.3 on Linux/x86<br /> |
| 62 | 2.3.3 on FreeBSD/x86<br /> |
| 63 | 2.3 on OSX/PPC<br /> |
| 64 | 2.2 on Linux/x86 |
| 65 | </blockquote> |
| 66 | |
| 67 | |
| 68 | |
| 69 | <h2>Testing the Redland Python interface</h2> |
| 70 | |
| 71 | <p>If you did the install above, run the python example program with:</p> |
| 72 | <pre> |
| 73 | python example.py |
| 74 | </pre> |
| 75 | <p>(Using the same chosen earlier)</p> |
| 76 | |
| 77 | <p>Otherwise, to run it in the source tree you need to find out the |
| 78 | architecture-specific sub-directory it created in the <em>build</em> |
| 79 | directory such as <em>build/lib.linux-i686-2.2</em> and run it with:</p> |
| 80 | <pre> |
| 81 | PYTHONPATH=build/lib.linux-i686-2.3 python example.py |
| 82 | </pre> |
| 83 | |
| 84 | <p>and the result should be:</p> |
| 85 | <pre> |
| 86 | found statement: {[http://www.dajobe.org/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"} |
| 87 | Parsing URI (file) ../data/dc.rdf |
| 88 | Parsing added 3 statements |
| 89 | Printing all statements |
| 90 | Statement: {[http://www.dajobe.org/], [http://purl.org/dc/elements/1.1/description], "The generic home page of Dave Beckett."} |
| 91 | Statement: {[http://www.dajobe.org/], [http://purl.org/dc/elements/1.1/title], "Dave Beckett's Home Page"} |
| 92 | Statement: {[http://www.dajobe.org/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"} |
| 93 | Statement: {[http://www.dajobe.org/], [http://purl.org/dc/elements/1.1/creator], "Dave Beckett"} |
| 94 | Writing model to test-out.rdf as rdf/xml |
| 95 | </pre> |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | <h2>Using the Redland Python API</h2> |
| 101 | |
| 102 | <p>Read the pydoc <a href="pydoc/RDF.html">Redland Python API</a> |
| 103 | for full details of the classes and methods provided along with |
| 104 | examples of use.</p> |
| 105 | |
| 106 | <p>The Python API is an object-based API reflecting the same structure |
| 107 | of the Redland objects with simple mappings between them:</p> |
| 108 | |
| 109 | <table border="1"> |
| 110 | <tr> |
| 111 | <th>Concept</th><th>Redland Class</th><th>Python Class</th><th>Purpose</th> |
| 112 | </tr> |
| 113 | <tr> |
| 114 | <td>Resource / Literal</td><td><span class="redland_class">librdf_node</span></td><td><a href="pydoc/RDF.html#Node"><tt>RDF.Node</tt></a></td> |
| 115 | <td>RDF Model & Syntax nodes</td> |
| 116 | </tr> |
| 117 | <tr> |
| 118 | <td>Statement / Triple</td><td><span class="redland_class">librdf_statement</span></td><td><a href="pydoc/RDF.html#Statement"><tt>RDF.Statement</tt></a></td> |
| 119 | <td>RDF Model & Syntax arcs (statements, triples) [isa Resource]</td> |
| 120 | </tr> |
| 121 | <tr> |
| 122 | <td>Model</td><td><span class="redland_class">librdf_model</span></td><td><a href="pydoc/RDF.html#Model"><tt>RDF.Model</tt></a></td> |
| 123 | <td>Set of <em>Statement</em>s usually held in one <em>Storage</em>.</td> |
| 124 | </tr> |
| 125 | <tr> |
| 126 | <td>Storage</td><td><span class="redland_class">librdf_storage</span></td><td><a href="pydoc/RDF.html#Storage"><tt>RDF.Storage</tt></a></td> |
| 127 | <td>Storage for <em>Model</em>s either persistant or in-memory.</td> |
| 128 | </tr> |
| 129 | <tr> |
| 130 | <td>Stream</td><td><span class="redland_class">librdf_stream</span></td><td><a href="pydoc/RDF.html#Stream"><tt>RDF.Stream</tt></a></td> |
| 131 | <td>Providing sequences of <em>Statement</em>s from <em>Parser</em>s, queries.</td> |
| 132 | </tr> |
| 133 | <tr> |
| 134 | <td>Parser</td><td><span class="redland_class">librdf_parser</span></td><td><a href="pydoc/RDF.html#Parser"><tt>RDF.Parser</tt></a></td> |
| 135 | <td>Syntaxes parsers delivering <em>Stream</em> of <em>Statement</em>s or writing to a <em>Model</em></td> |
| 136 | </tr> |
| 137 | <tr> |
| 138 | <td>Query</td><td><span class="redland_class">librdf_query</span></td><td><a href="pydoc/RDF.html#Query"><tt>RDF.Query</tt></a></td> |
| 139 | <td>Querying of an <em>Model</em> delivering a <em>QueryResults</em></td> |
| 140 | </tr> |
| 141 | <tr> |
| 142 | <td>QueryResults</td><td><span class="redland_class">librdf_query_results</span></td><td><a href="pydoc/RDF.html#QueryResults"><tt>RDF.QueryResults</tt></a></td> |
| 143 | <td>Results of applying an <em>Query</em> to a <em>Model</em> giving either variable bindings with <em>Node</em> values or <em>Stream</em> of <em>Statement</em>s</td> |
| 144 | </tr> |
| 145 | <tr> |
| 146 | <td>Serializer</td><td><span class="redland_class">librdf_serializer</span></td><td><a href="pydoc/RDF.html#Serializer"><tt>RDF.Serializer</tt></a></td> |
| 147 | <td>Serializes a <em>Model</em> into a syntax such as RDF/XML</td> |
| 148 | </tr> |
| 149 | <tr> |
| 150 | <td>Iterator</td><td><span class="redland_class">librdf_iterator</span></td><td><a href="pydoc/RDF.html#Iterator"><tt>RDF.Iterator</tt></a></td> |
| 151 | <td>Enumerating lists (of <em>Node</em>) from queries.</td> |
| 152 | </tr> |
| 153 | <tr> |
| 154 | <td>URI</td><td><span class="redland_class">librdf_uri</span></td><td><a href="pydoc/RDF.html#Uri"><tt>RDF.Uri</tt></a></td> |
| 155 | <td>Provides URIs for <em>Resource</em>s, <em>Parser</em>s, ...</td> |
| 156 | </tr> |
| 157 | <tr> |
| 158 | <td>World</td><td> </td><td><a href="pydoc/RDF.html#World"><tt>RDF.World</tt></a></td> |
| 159 | <td>RDF wrapper class handling Redland startup/shutdown</td> |
| 160 | </tr> |
| 161 | <tr> |
| 162 | <td>Digest</td><td><span class="redland_class">librdf_digest</span></td><td> </td> |
| 163 | <td>Internal content digest class</td> |
| 164 | </tr> |
| 165 | <tr> |
| 166 | <td>Hash</td><td><span class="redland_class">librdf_hash</span></td><td> </td> |
| 167 | <td>Internal key:value maps class</td> |
| 168 | </tr> |
| 169 | </table> |
| 170 | |
| 171 | |
| 172 | <hr /> |
| 173 | |
| 174 | <p>Copyright (C) 2000-2007 <a href="http://www.dajobe.org/">Dave Beckett</a>, Copyright (C) 2000-2005 <a href="http://www.bristol.ac.uk/">University of Bristol</a></p> |
| 175 | |
| 176 | </body> |
| 177 | </html> |