Python "wrapper" for Piglet

We are building a "wrapper" for the Piglet library (libpiglet), allowing the creation and use of Piglet RDF triplestores from Python programs. To make use of it, you have to import the module with

import piglet

In Piglet, nodes - resources (including bnodes) and literals - are represented as integers. Resources are positive, literals are negative. The value 0 is the "null node", and can be used as a wildcard when matching nodes or triples. Triples are represented as three-element tuples (duh!).

module piglet

The module implements only one function:

piglet.open(filename)

class piglet.DB

The class DB implements the following methods:

close()

query(subject, predicate, object[, source])

sources(subject, predicate, object)

add(subject, predicate, object, source[, temporary])

delete(subject, predicate, object, source[, temporary])

count(subject, predicate, object, source[, temporary])

info(node)

node(uri)

literal(string[, datatype[, language]])

load(source[, append])

nodeToString(node)

tripleToString(subject, predicate, object)

expand(qname)

reverseExpand(uri)

addNamespace(prefix, uri)

delNamespace(prefix)

match(pattern)

module pigletserver

The module implements a simple HTTP server that can be used to call the Piglet API; it serves back the API call results directly (as JSON, using json-py as the translator). Technically, the server is implemented as the classs pigletserver.PigletServer and pigletserver.PigletServerHandler. As an example, to start the server for Piglet database file "test.data" on port 8081, use this:

python pigletserver.py test.data 8081

Once the server is running, you can call it with HTTP GET where the entire call is encoded in the URL. For example, to call piglet.DB.query(1, 2, 3) you use the following URL:

http://localhost:8081/query?s=1&p=2&o=3

PigletToolkit/PigletForPython (last edited 2008-09-20 12:21:27 by OraLassila)