Giovanni Casini
Giovanni Casini

Reputation: 39

How to query Virtuoso SPARQL endpoint from Python with user-specific credentials to test performance based on graph permissions?

I am running Virtuoso on a Docker container on localhost:8890. My goal is to test whether adding permissions/restrictions to certain graphs results in time inefficiencies when querying. For this reason, through Virtuoso Conductor, I have created users, other than the dba, with different permissions regarding access to the graphs/ontologies I have loaded. Through the ISQL interface on Virtuoso Conductor (localhost:8890/conductor/isql.vspx), it is possible to run queries by choosing which user is executing it directly from the interface, but there is no way to estimate the response time. Additionally, I would like to do this by querying the endpoint from Python, for example.

For now, I have written this code that queries the SPARQL endpoint (localhost:8890/sparql) and returns the correct results but executes as the default dba (I believe), and I have not found any working way to specify which user is executing the query:

from SPARQLWrapper import SPARQLWrapper, CSV

sparql = SPARQLWrapper('http://localhost:8890/sparql')
sparql.setQuery('''
PREFIX sem:<http://www.semanticweb.org/ontologies/TravelApp_Ontology#>
SELECT * WHERE {?s a sem:Skiing}
''')
sparql.setReturnFormat(CSV)
qres = sparql.query().convert().decode('utf-8')

print(qres)

Among others, I also tried sparql = SPARQLWrapper('http://username:password@localhost:8890/sparql'), but it doesn't work. Do you know of a way to execute queries from Python to Virtuoso, specifying which user is executing it, or any other way that could work? Thanks in advance!

Upvotes: 1

Views: 25

Answers (0)

Related Questions