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
./db/
./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>
./graphimport hello.ntServer 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"
./dumpgraphServer 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))]
./query "SELECT ?label WHERE { ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label }"
[{'label': rdflib.Literal('Hello',language=None,datatype=None)}]
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.
SELECT ?broken { ?typo here }
Traceback (most recent call last): File "sparqlhttp-1.0/sparqlhttp/serve.py", line 48, in getQuery results = self.graph.queryd(query) File "sparqlhttp-1.0/sparqlhttp/dictquery.py", line 80, in queryd initNs=self.initNs) File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/Graph.py", line 644, in query return plugin.get('SPARQLQueryResult',QueryResult)(p.query(strOrQuery, initBindings, initNs, DEBUG)) File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/sparql/bison/Processor.py", line 26, in query strOrQuery = Parse(strOrQuery, DEBUG) File "/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/sparql/bison/Processor.py", line 16, in Parse return p.parse(unicode(query,'utf-8')) SyntaxError: lexical error at line 1, column 30: no action found for 'here }'
SELECT ?broken { ?typo here }Again, as one line:
total secs (per) | count | query (with sample initBindings) | bound | avg rows | sources |
---|---|---|---|---|---|
0.01 (0.0110) | 1 | SELECT ?s ?p ?o WHERE { ?s ?p ?o } | () | 2.0 | dumpgraph:9 |
cd test trial test_dictquery.py test_remotegraph.py # all these should work trial test_syncimport.py # this one might not do as well