pySesame - a Python wrapper for Sesame
Sesame (http://openrdf.org)
is an open source
RDF
Schema-based storage and querying facility.
pySesame is a Python wrapper for Sesame's REST HTTP API, as described
in chapter 8 of the Sesame Manual.
Now you can easily do the following from your Python script:
- Log in
- Log out
- Request a list of available repositories
- Evaluate a SeRQL-select, RQL or RDQL query
- Evaluate a SeRQL-construct query
- Extract RDF from a repository
- Uploading data to a repository
- Add data from the web to a repository
- Clear a repository
- Remove statements
RQL, RDQL and SeRQL queries will return results as Python data structures,
HTML or RDF.
Download:
pySesame at SemWebCentral.
Example usage:
>>> from pySesame import SesameConnection
>>> connection = SesameConnection('feinsteinhs.org:8180', '/sesame/')
>>> connection.login('test', 'pySesame')
>>> connection.repositories()
[{'writeable': u'true', 'readable': u'true', 'id': u'pySesame', 'title': u'pySesame Test Suite'}]
>>> connection.uploadURL('pySesame', 'http://burningbird.net/articles/monsters1.rdf')
1
>>> rdqlQuery = """SELECT ?date
... WHERE
... (?resource, , ),
... (?resource, ,?value),
... (?resource, , ?date)
... AND (?value eq "Add")
... USING pstcn FOR ,
... rdf for ,
... dc for """
>>> connection.tableQuery('pySesame', 'RDQL', rdqlQuery)
{'header': [u'date'], 'tuples': [[{'type': u'literal', 'value': u'1998-01-01T00:00:00-05:00'}]]}
>>> connection.logout()
Logged out successfully
Status and ToDo:
pySesame
should be pretty complete. The test suite covers most, but not all of the functionality.
Outstanding issues:
-
The return value for succesfull login is currently 'None'; should be 'True'.
Unsuccesfull login in will throw a nice SesameException.
-
The testsuite will return 'failures' if the RDF/XML response format
differs from that of the the original testing server. Need to check the query results
in sorted n-triples (which are canonical).
Prerequisites
-
Python 2.1 or greater.
-
If you get an error related to your XML parser, you probably need to install
PyXML.
Contact
Tom Hoffman,
*-pike