Ted Lawless

Connecting Python's RDFLib to AWS Neptune


I've written previously about using Python's RDFLib to connect to various triple stores. For a current project, I'm using Amazon Neptune as a triple store and the RDFLib SPARQLStore implemenation did not work out of the box. I thought I would share my solution.

The problem

Neptune returns ntriples by default and RDFLib, by default in version 4.2.2, is expecting CONSTRUCT queries to return RDF/XML. The solution is to override RDFLib's SPARQLStore to explictly request RDF/XML from Neptune via HTTP content negotiation.

Once this is in place, you can query and update Neptune via SPARQL with RDFLib the same way that you would other triple stores.


If you are interested in working with Neptune using RDFLib, here's a "NeptuneStore" and "NeptuneUpdateStore" implementation that you can use.