rdflib.plugin.register('sparql', rdflib.query.Processor,
    'rdfextras.sparql.processor', 'Processor')
rdflib.plugin.register('sparql', rdflib.query.Result,
    'rdfextras.sparql.query', 'SPARQLQueryResult')
query = """
SELECT ?seq_index ?name ?surname WHERE {
     <http://www.ncbi.nlm.nih.gov/pubmed/18273724> bib:authors ?seq .
     ?seq ?seq_index ?seq_bnode .
     ?seq_bnode foaf:givenname ?name .
     ?seq_bnode foaf:surname ?surname .
}
"""
for row in sorted(g.query(query, initNs=dict(rdf=RDF, foaf=FOAF, bib=BIB)),
    key=lambda x: int(x[0][44:])):
    print('Author(%s) %s %s' % (row[0][44:], row[1], row[2]))
How to access members of an rdf list with rdflib (or plain sparql)