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:

- `prepareQuery` –

  Parse and translate a SPARQL Query

- `prepareUpdate` –

  Parse and translate a SPARQL Update

- `processUpdate` –

  Process a SPARQL Update Request

Attributes:

- `CUSTOM_EVALS` –

  Custom evaluation functions

## `` 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 <uri> and FROM NAMED <uri> 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`

    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33

    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`

    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48

    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`

    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64

    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
        )