HTTP SPARQL server for twisted and rdflib

This library is for programs that use twisted for networking, use rdflib for RDF, and want to do sparql over http. It contains a client and a server, but you should be able to mix and match with other sparql clients and servers.

Classes
RemoteGraph twisted web client that talks to SPARQLResource (or other sparql-over-http servers)
⇑ HTTP ⇓
SPARQLResource twisted web resource that supports various GET/POST commands
Graph2 slightly different API for the rdflib graph class
ConjunctiveGraph (from rdflib)

There is also a LocalGraph class, which presents exactly the same API as RemoteGraph, but it talks to an in-process rdflib graph. This is convenient for testing your async RemoteGraph code without bothering to setup the http connection.


# this code will work whether graph is a RemoteGraph or a LocalGraph

    def method(self):
        d = graph.remoteLabel(subj)
        d.addCallback(self.withLabel)

    def withLabel(self, label):
        print label

Download

sparqlhttp-1.2.tar.gz (2008-02-06) changelog
sparqlhttp-1.1.tar.gz (2007-08-07) changelog
sparqlhttp-1.0.tar.gz (2007-03-01)

Requirements

Demo (updated for version 1.2)

  1. Start a server, creating a new berkeleydb instance in ./db/
    bin/sparqlserve --home db
    2007/01/22 00:58 -0700 [-] Log opened.
    2007/01/22 00:58 -0700 [-] twisted.web.server.Site starting on 9991
    2007/01/22 00:58 -0700 [-] Starting factory <twisted.web.server.Site instance at 0xb7646aac>
    
  2. In another shell, parse some NT and POST it to the server. The post will be to "/add?context=http://example.org#context" with data consisting of NT statements. That part of my protocol is not part of any standard.
    bin/graphimport hello.nt
    Server says:
    2007/01/22 01:14 -0700 [HTTPChannel,0,127.0.0.1] 127.0.0.1 - - [22/Jan/2007:08:14:08 +0000] "POST /add?context=http%3A//example.org/%23context HTTP/1.0" 200 2 "-" "Twisted PageGetter"
  3. GET the query "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" from the server. This uses the standard SPARQL query and results formats.
    bin/dumpgraph
    Server says:
    2007/01/22 01:15 -0700 [HTTPChannel,1,127.0.0.1] 127.0.0.1 - - [22/Jan/2007:08:15:32 +0000] "GET /?query=SELECT%20%3Fs%20%3Fp%20%3Fo%20WHERE%20%7B%20%3Fs%20%3Fp%20%3Fo%20%7D HTTP/1.0" 200 617 "-" "Twisted PageGetter"
    Client says:
    [(u'http://example.org/hello',
      u'http://example.org/to',
      rdflib.Literal('world',language=None,datatype=None)),
     (u'http://example.org/hello',
      u'http://www.w3.org/2000/01/rdf-schema#label',
      rdflib.Literal('Hello',language=None,datatype=None))]
    
  4. Do an arbitrary query on the server.
    bin/query "SELECT ?label WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label }"
    [{'label': rdflib.Literal('Hello',language=None,datatype=None)}]
    
  5. Check out the server diagnostics at http://localhost:9991/

    I deliberately made an error request to cause the the traceback below. The table at the bottom is really nice for large programs, since it shows what lines in your code made the various queries.

  6. Try running the tests. They use twisted trial and they run from the test directory:
    cd test
    trial test_dictquery.py test_remotegraph.py    # these mostly work (they all work with a hacked rdflib)
    trial test_syncimport.py   # this one might not do as well (not sure why- it works in my kit)