results Package

csvresults Module

This module implements a parser and serializer for the CSV SPARQL result formats

http://www.w3.org/TR/sparql11-results-csv-tsv/

class rdflib.plugins.sparql.results.csvresults.CSVResultParser[source]

Bases: rdflib.query.ResultParser

__init__()[source]
__module__ = 'rdflib.plugins.sparql.results.csvresults'
convertTerm(t)[source]
parse(source)[source]
parseRow(row, v)[source]
class rdflib.plugins.sparql.results.csvresults.CSVResultSerializer(result)[source]

Bases: rdflib.query.ResultSerializer

__init__(result)[source]
__module__ = 'rdflib.plugins.sparql.results.csvresults'
serialize(stream, encoding='utf-8')[source]
serializeTerm(term, encoding)[source]

jsonlayer Module

Thin abstraction layer over the different available modules for decoding and encoding JSON data.

This module currently supports the following JSON modules:

The default behavior is to use simplejson if installed, and otherwise fallback to the standard library module. To explicitly tell SPARQLWrapper which module to use, invoke the use() function with the module name:

import jsonlayer
jsonlayer.use('cjson')

In addition to choosing one of the above modules, you can also configure SPARQLWrapper to use custom decoding and encoding functions:

import jsonlayer
jsonlayer.use(decode=my_decode, encode=my_encode)
rdflib.plugins.sparql.results.jsonlayer.decode(string)[source]

Decode the given JSON string.

Parameters:string (basestring) – the JSON string to decode
Returns:the corresponding Python data structure
Return type:object
rdflib.plugins.sparql.results.jsonlayer.encode(obj)[source]

Encode the given object as a JSON string.

Parameters:obj (object) – the Python data structure to encode
Returns:the corresponding JSON string
Return type:basestring
rdflib.plugins.sparql.results.jsonlayer.use(module=None, decode=None, encode=None)[source]

Set the JSON library that should be used, either by specifying a known module name, or by providing a decode and encode function.

The modules “simplejson”, “cjson”, and “json” are currently supported for the module parameter.

If provided, the decode parameter must be a callable that accepts a JSON string and returns a corresponding Python data structure. The encode callable must accept a Python data structure and return the corresponding JSON string. Exceptions raised by decoding and encoding should be propagated up unaltered.

Parameters:
  • module (str or module) – the name of the JSON library module to use, or the module object itself
  • decode (callable) – a function for decoding JSON strings
  • encode (callable) – a function for encoding objects as JSON strings

jsonresults Module

class rdflib.plugins.sparql.results.jsonresults.JSONResult(json)[source]

Bases: rdflib.query.Result

__init__(json)[source]
__module__ = 'rdflib.plugins.sparql.results.jsonresults'
class rdflib.plugins.sparql.results.jsonresults.JSONResultParser[source]

Bases: rdflib.query.ResultParser

__module__ = 'rdflib.plugins.sparql.results.jsonresults'
parse(source)[source]
class rdflib.plugins.sparql.results.jsonresults.JSONResultSerializer(result)[source]

Bases: rdflib.query.ResultSerializer

__init__(result)[source]
__module__ = 'rdflib.plugins.sparql.results.jsonresults'
serialize(stream, encoding=None)[source]
rdflib.plugins.sparql.results.jsonresults.parseJsonTerm(d)[source]

rdflib object (Literal, URIRef, BNode) for the given json-format dict.

input is like:
{ ‘type’: ‘uri’, ‘value’: ‘http://famegame.com/2006/01/username‘ } { ‘type’: ‘literal’, ‘value’: ‘drewp’ }
rdflib.plugins.sparql.results.jsonresults.termToJSON(self, term)[source]

rdfresults Module

class rdflib.plugins.sparql.results.rdfresults.RDFResult(source, **kwargs)[source]

Bases: rdflib.query.Result

__init__(source, **kwargs)[source]
__module__ = 'rdflib.plugins.sparql.results.rdfresults'
class rdflib.plugins.sparql.results.rdfresults.RDFResultParser[source]

Bases: rdflib.query.ResultParser

__module__ = 'rdflib.plugins.sparql.results.rdfresults'
parse(source, **kwargs)[source]

tsvresults Module

This implements the Tab Separated SPARQL Result Format

It is implemented with pyparsing, reusing the elements from the SPARQL Parser

class rdflib.plugins.sparql.results.tsvresults.TSVResultParser[source]

Bases: rdflib.query.ResultParser

__module__ = 'rdflib.plugins.sparql.results.tsvresults'
convertTerm(t)[source]
parse(source)[source]

xmlresults Module

rdflib.plugins.sparql.results.xmlresults.RESULTS_NS_ET = u'{http://www.w3.org/2005/sparql-results#}'

A Parser for SPARQL results in XML:

http://www.w3.org/TR/rdf-sparql-XMLres/

Bits and pieces borrowed from: http://projects.bigasterisk.com/sparqlhttp/

Authors: Drew Perttula, Gunnar Aastrand Grimnes

class rdflib.plugins.sparql.results.xmlresults.SPARQLXMLWriter(output, encoding='utf-8')[source]

Python saxutils-based SPARQL XML Writer

__init__(output, encoding='utf-8')[source]
__module__ = 'rdflib.plugins.sparql.results.xmlresults'
close()[source]
write_ask(val)[source]
write_binding(name, val)[source]
write_end_result()[source]
write_header(allvarsL)[source]
write_results_header()[source]
write_start_result()[source]
class rdflib.plugins.sparql.results.xmlresults.XMLResult(source)[source]

Bases: rdflib.query.Result

__init__(source)[source]
__module__ = 'rdflib.plugins.sparql.results.xmlresults'
class rdflib.plugins.sparql.results.xmlresults.XMLResultParser[source]

Bases: rdflib.query.ResultParser

__module__ = 'rdflib.plugins.sparql.results.xmlresults'
parse(source)[source]
class rdflib.plugins.sparql.results.xmlresults.XMLResultSerializer(result)[source]

Bases: rdflib.query.ResultSerializer

__init__(result)[source]
__module__ = 'rdflib.plugins.sparql.results.xmlresults'
serialize(stream, encoding='utf-8')[source]
rdflib.plugins.sparql.results.xmlresults.parseTerm(element)[source]

rdflib object (Literal, URIRef, BNode) for the given elementtree element