Introducing Pynappl
Over the summer I spent some time working on a Python library for working with the Talis Platform. I’ve spent a lot of time developing the PHP-based Moriarty library and I’ve been wanting to apply that experience to other languages. Leigh has made good progress on the Ruby front with Pho and we have a nascent Java-based client: Penry. Considering Python’s excellent RDF support it seemed the natural choice to tackle next.
Pynappl is the resulting library. It’s still very early in its evolution and so has lots of rough edges, gaps and rather dubious design choices. So far Pynappl’s feature set has been driven by the real applications I have been working with so there is a distinct bias towards data loading and management of stores. The Store class is the workhorse of the library and contains methods for loading RDF, running SPARQL queries, scheduling jobs and reading and writing of field/predicate maps and query profiles.
In keeping with my general philosophy for building RESTful applications, the HTTP based methods on the Store class make it very obvious that you are working with a fallible network by returning a tuple containing the HTTP reswponse and the body of the response. Its up to you to use or ignore the response as you see fit for your application. Many methods attempt to interpret the results of the method call but this can be switched off using an argument called “raw”. For example this code takes advantage of the interpretation and parsing of the SPARQL results:
store = pynappl.Store(store_uri, username, password)
(response, body) = store.select("select * where {?s a ?o} limit 10")
(sparql_header, results) = body
for result in results:
print "%s (a %s)" % (str(result['s']), str(result['o']))
This can be switched off to get at the raw response body:
(response, body) = store.select("select * where {?s a ?o} limit 10", True)
print body
Also included is a command line application called tstore that wraps up a lot of these operations, including waiting for batch operations to complete. For example, to reset a store and load data into it takes just two lines:
./tstore --store mystore --user username --password xxxx reset --wait
./tstore --store mystore --user username --password xxxx store -f data.rdf
Please take a look at Pynappl and let me know what you think or of you’d like to get involved and help out.
About Pynappl… Pynappl is a simple open source Python library for working with the Talis Platform. Currently it is focussed mainly on managing data loading and manipulation of Talis Platform stores. Pynappl is an early alpha and is substantially incomplete (we’re looking for interested contributors. You can read more about Pynappl at its Google Code project page

