Skip to content

sparql

SPARQL implementation for RDFLib

New in version 4.0

Modules:

  • aggregates

    Aggregation functions

  • algebra

    Converting the ‘parse-tree’ output of pyparsing to a SPARQL Algebra expression

  • datatypes

    Utility functions for supporting the XML Schema Datatypes hierarchy

  • evaluate

    These method recursively evaluate the SPARQL Algebra

  • evalutils
  • operators

    This contains evaluation functions for expressions

  • parser

    SPARQL 1.1 Parser

  • parserutils

    NOTE: PyParsing setResultName/call provides a very similar solution to this

  • processor

    Code for tying SPARQL Engine into RDFLib

  • results

    Parsers and serializers for SPARQL Result formats

  • sparql
  • update

    Code for carrying out Update Operations

Functions:

Attributes:

CUSTOM_EVALS module-attribute

CUSTOM_EVALS = {}

Custom evaluation functions

These must be functions taking (ctx, part) and raise NotImplementedError if they cannot handle a certain part

PLUGIN_ENTRY_POINT module-attribute

PLUGIN_ENTRY_POINT = 'rdf.plugins.sparqleval'

SPARQL_DEFAULT_GRAPH_UNION module-attribute

SPARQL_DEFAULT_GRAPH_UNION = True

If True - the default graph in the RDF Dataset is the union of all named graphs (like RDFLib’s ConjunctiveGraph)

SPARQL_LOAD_GRAPHS module-attribute

SPARQL_LOAD_GRAPHS = True

If True, using FROM and FROM NAMED will load/parse more data

__all__ module-attribute

__all__ = ['prepareQuery', 'prepareUpdate', 'processUpdate', 'operators', 'parser', 'parserutils', 'CUSTOM_EVALS']

all_entry_points module-attribute

all_entry_points = entry_points()

prepareQuery

prepareQuery(queryString: str, initNs: Optional[Mapping[str, Any]] = None, base: Optional[str] = None) -> Query

Parse and translate a SPARQL Query

Source code in rdflib/plugins/sparql/processor.py
def prepareQuery(
    queryString: str,
    initNs: Optional[Mapping[str, Any]] = None,
    base: Optional[str] = None,
) -> Query:
    """
    Parse and translate a SPARQL Query
    """
    if initNs is None:
        initNs = {}
    ret = translateQuery(parseQuery(queryString), base, initNs)
    ret._original_args = (queryString, initNs, base)
    return ret

prepareUpdate

prepareUpdate(updateString: str, initNs: Optional[Mapping[str, Any]] = None, base: Optional[str] = None) -> Update

Parse and translate a SPARQL Update

Source code in rdflib/plugins/sparql/processor.py
def prepareUpdate(
    updateString: str,
    initNs: Optional[Mapping[str, Any]] = None,
    base: Optional[str] = None,
) -> Update:
    """
    Parse and translate a SPARQL Update
    """
    if initNs is None:
        initNs = {}
    ret = translateUpdate(parseUpdate(updateString), base, initNs)
    ret._original_args = (updateString, initNs, base)
    return ret

processUpdate

processUpdate(graph: Graph, updateString: str, initBindings: Optional[Mapping[str, Identifier]] = None, initNs: Optional[Mapping[str, Any]] = None, base: Optional[str] = None) -> None

Process a SPARQL Update Request returns Nothing on success or raises Exceptions on error

Source code in rdflib/plugins/sparql/processor.py
def processUpdate(
    graph: Graph,
    updateString: str,
    initBindings: Optional[Mapping[str, Identifier]] = None,
    initNs: Optional[Mapping[str, Any]] = None,
    base: Optional[str] = None,
) -> None:
    """
    Process a SPARQL Update Request
    returns Nothing on success or raises Exceptions on error
    """
    evalUpdate(
        graph, translateUpdate(parseUpdate(updateString), base, initNs), initBindings
    )