# rdflib.plugins.sparql package

## Subpackages

- rdflib.plugins.sparql.results package
  - Submodules
  - rdflib.plugins.sparql.results.csvresults module
    - `CSVResultParser`
      - `CSVResultParser.__annotations__`
      - `CSVResultParser.__firstlineno__`
      - `CSVResultParser.__init__()`
      - `CSVResultParser.__module__`
      - `CSVResultParser.__static_attributes__`
      - `CSVResultParser.convertTerm()`
      - `CSVResultParser.parse()`
      - `CSVResultParser.parseRow()`
    - `CSVResultSerializer`
      - `CSVResultSerializer.__annotations__`
      - `CSVResultSerializer.__firstlineno__`
      - `CSVResultSerializer.__init__()`
      - `CSVResultSerializer.__module__`
      - `CSVResultSerializer.__static_attributes__`
      - `CSVResultSerializer.serialize()`
      - `CSVResultSerializer.serializeTerm()`
  - rdflib.plugins.sparql.results.graph module
    - `GraphResultParser`
      - `GraphResultParser.__annotations__`
      - `GraphResultParser.__firstlineno__`
      - `GraphResultParser.__module__`
      - `GraphResultParser.__static_attributes__`
      - `GraphResultParser.parse()`
  - rdflib.plugins.sparql.results.jsonresults module
    - `JSONResult`
      - `JSONResult.__annotations__`
      - `JSONResult.__firstlineno__`
      - `JSONResult.__init__()`
      - `JSONResult.__module__`
      - `JSONResult.__static_attributes__`
    - `JSONResultParser`
      - `JSONResultParser.__annotations__`
      - `JSONResultParser.__firstlineno__`
      - `JSONResultParser.__module__`
      - `JSONResultParser.__static_attributes__`
      - `JSONResultParser.parse()`
    - `JSONResultSerializer`
      - `JSONResultSerializer.__annotations__`
      - `JSONResultSerializer.__firstlineno__`
      - `JSONResultSerializer.__init__()`
      - `JSONResultSerializer.__module__`
      - `JSONResultSerializer.__static_attributes__`
      - `JSONResultSerializer.serialize()`
    - `parseJsonTerm()`
    - `termToJSON()`
  - rdflib.plugins.sparql.results.rdfresults module
    - `RDFResult`
      - `RDFResult.__annotations__`
      - `RDFResult.__firstlineno__`
      - `RDFResult.__init__()`
      - `RDFResult.__module__`
      - `RDFResult.__static_attributes__`
    - `RDFResultParser`
      - `RDFResultParser.__annotations__`
      - `RDFResultParser.__firstlineno__`
      - `RDFResultParser.__module__`
      - `RDFResultParser.__static_attributes__`
      - `RDFResultParser.parse()`
  - rdflib.plugins.sparql.results.tsvresults module
    - `TSVResultParser`
      - `TSVResultParser.__annotations__`
      - `TSVResultParser.__firstlineno__`
      - `TSVResultParser.__module__`
      - `TSVResultParser.__static_attributes__`
      - `TSVResultParser.convertTerm()`
      - `TSVResultParser.parse()`
  - rdflib.plugins.sparql.results.txtresults module
    - `TXTResultSerializer`
      - `TXTResultSerializer.__annotations__`
      - `TXTResultSerializer.__firstlineno__`
      - `TXTResultSerializer.__module__`
      - `TXTResultSerializer.__static_attributes__`
      - `TXTResultSerializer.serialize()`
  - rdflib.plugins.sparql.results.xmlresults module
    - `SPARQLXMLWriter`
      - `SPARQLXMLWriter.__dict__`
      - `SPARQLXMLWriter.__firstlineno__`
      - `SPARQLXMLWriter.__init__()`
      - `SPARQLXMLWriter.__module__`
      - `SPARQLXMLWriter.__static_attributes__`
      - `SPARQLXMLWriter.__weakref__`
      - `SPARQLXMLWriter.close()`
      - `SPARQLXMLWriter.write_ask()`
      - `SPARQLXMLWriter.write_binding()`
      - `SPARQLXMLWriter.write_end_result()`
      - `SPARQLXMLWriter.write_header()`
      - `SPARQLXMLWriter.write_results_header()`
      - `SPARQLXMLWriter.write_start_result()`
    - `XMLResult`
      - `XMLResult.__annotations__`
      - `XMLResult.__firstlineno__`
      - `XMLResult.__init__()`
      - `XMLResult.__module__`
      - `XMLResult.__static_attributes__`
    - `XMLResultParser`
      - `XMLResultParser.__annotations__`
      - `XMLResultParser.__firstlineno__`
      - `XMLResultParser.__module__`
      - `XMLResultParser.__static_attributes__`
      - `XMLResultParser.parse()`
    - `XMLResultSerializer`
      - `XMLResultSerializer.__annotations__`
      - `XMLResultSerializer.__firstlineno__`
      - `XMLResultSerializer.__init__()`
      - `XMLResultSerializer.__module__`
      - `XMLResultSerializer.__static_attributes__`
      - `XMLResultSerializer.serialize()`
    - `parseTerm()`
  - Module contents

## Submodules

## rdflib.plugins.sparql.aggregates module

Aggregation functions

class rdflib.plugins.sparql.aggregates.Accumulator(aggregation)

  Bases: `object`

  abstract base class for different aggregation functions

  Parameters:

    aggregation (`CompValue`)

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.aggregates', '__firstlineno__': 33, '__doc__': 'abstract base class for different aggregation functions', '__init__': <function Accumulator.__init__>, 'dont_care': <function Accumulator.dont_care>, 'use_row': <function Accumulator.use_row>, 'set_value': <function Accumulator.set_value>, '__static_attributes__': ('distinct', 'expr', 'seen', 'use_row', 'var'), '__dict__': <attribute '__dict__' of 'Accumulator' objects>, '__weakref__': <attribute '__weakref__' of 'Accumulator' objects>, '__annotations__': {'get_value': 'Callable[[], Optional[Literal]]', 'update': 'Callable[[FrozenBindings, Aggregator], None]', 'seen': 'Set[Any]'}})
  __firstlineno__ = 33
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('distinct', 'expr', 'seen', 'use_row', 'var')
  __weakref__

    list of weak references to the object

  dont_care(row)

    skips distinct test

    Parameters:

      row (`FrozenBindings`)

    Return type:

      `bool`

  set_value(bindings)

    sets final value in bindings

    Parameters:

      bindings (`MutableMapping`[`Variable`, `Identifier`])

    Return type:

      `None`

  use_row(row)

    tests distinct with set

    Parameters:

      row (`FrozenBindings`)

    Return type:

      `bool`

class rdflib.plugins.sparql.aggregates.Aggregator(aggregations)

  Bases: `object`

  combines different Accumulator objects

  Parameters:

    aggregations (`List`[`CompValue`])

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.aggregates', '__firstlineno__': 281, '__doc__': 'combines different Accumulator objects', 'accumulator_classes': {'Aggregate_Count': <class 'rdflib.plugins.sparql.aggregates.Counter'>, 'Aggregate_Sample': <class 'rdflib.plugins.sparql.aggregates.Sample'>, 'Aggregate_Sum': <class 'rdflib.plugins.sparql.aggregates.Sum'>, 'Aggregate_Avg': <class 'rdflib.plugins.sparql.aggregates.Average'>, 'Aggregate_Min': <class 'rdflib.plugins.sparql.aggregates.Minimum'>, 'Aggregate_Max': <class 'rdflib.plugins.sparql.aggregates.Maximum'>, 'Aggregate_GroupConcat': <class 'rdflib.plugins.sparql.aggregates.GroupConcat'>}, '__init__': <function Aggregator.__init__>, 'update': <function Aggregator.update>, 'get_bindings': <function Aggregator.get_bindings>, '__static_attributes__': ('accumulators', 'bindings'), '__dict__': <attribute '__dict__' of 'Aggregator' objects>, '__weakref__': <attribute '__weakref__' of 'Aggregator' objects>, '__annotations__': {'bindings': 'Dict[Variable, Identifier]', 'accumulators': 'Dict[str, Accumulator]'}})
  __firstlineno__ = 281
  __init__(aggregations)
    Parameters:

      aggregations (`List`[`CompValue`])

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('accumulators', 'bindings')
  __weakref__

    list of weak references to the object

  accumulator_classes = {'Aggregate_Avg': <class 'rdflib.plugins.sparql.aggregates.Average'>, 'Aggregate_Count': <class 'rdflib.plugins.sparql.aggregates.Counter'>, 'Aggregate_GroupConcat': <class 'rdflib.plugins.sparql.aggregates.GroupConcat'>, 'Aggregate_Max': <class 'rdflib.plugins.sparql.aggregates.Maximum'>, 'Aggregate_Min': <class 'rdflib.plugins.sparql.aggregates.Minimum'>, 'Aggregate_Sample': <class 'rdflib.plugins.sparql.aggregates.Sample'>, 'Aggregate_Sum': <class 'rdflib.plugins.sparql.aggregates.Sum'>}
  get_bindings()

    calculate and set last values

    Return type:

      `Mapping`[`Variable`, `Identifier`]

  update(row)

    update all own accumulators

    Parameters:

      row (`FrozenBindings`)

    Return type:

      `None`

class rdflib.plugins.sparql.aggregates.Average(aggregation)

  Bases: `Accumulator`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 146
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('counter', 'datatype', 'sum')
  get_value()
    Return type:

      `Literal`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

class rdflib.plugins.sparql.aggregates.Counter(aggregation)

  Bases: `Accumulator`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 63
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('eval_row', 'value')
  eval_full_row(row)
    Parameters:

      row (`FrozenBindings`)

    Return type:

      `FrozenBindings`

  eval_row(row)
    Parameters:

      row (`FrozenBindings`)

    Return type:

      `Identifier`

  get_value()
    Return type:

      `Literal`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

  use_row(row)

    tests distinct with set

    Parameters:

      row (`FrozenBindings`)

    Return type:

      `bool`

class rdflib.plugins.sparql.aggregates.Extremum(aggregation)

  Bases: `Accumulator`

  abstract base class for Minimum and Maximum

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 182
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('use_row', 'value')
  set_value(bindings)

    sets final value in bindings

    Parameters:

      bindings (`MutableMapping`[`Variable`, `Identifier`])

    Return type:

      `None`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

class rdflib.plugins.sparql.aggregates.GroupConcat(aggregation)

  Bases: `Accumulator`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {'value': 'List[Literal]'}
  __firstlineno__ = 248
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('separator', 'value')
  get_value()
    Return type:

      `Literal`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

  value: `List`[`Literal`]

class rdflib.plugins.sparql.aggregates.Maximum(aggregation)

  Bases: `Extremum`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 220
  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ()
  compare(val1, val2)
    Parameters:

      - val1 (`TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`))

      - val2 (`TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`))

    Return type:

      `TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`)

class rdflib.plugins.sparql.aggregates.Minimum(aggregation)

  Bases: `Extremum`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 215
  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ()
  compare(val1, val2)
    Parameters:

      - val1 (`TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`))

      - val2 (`TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`))

    Return type:

      `TypeVar`(`_ValueT`, `Variable`, `BNode`, `URIRef`, `Literal`)

class rdflib.plugins.sparql.aggregates.Sample(aggregation)

  Bases: `Accumulator`

  takes the first eligible value

  __annotations__ = {}
  __firstlineno__ = 225
  __init__(aggregation)
  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('use_row',)
  get_value()
    Return type:

      `None`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

class rdflib.plugins.sparql.aggregates.Sum(aggregation)

  Bases: `Accumulator`

  Parameters:

    aggregation (`CompValue`)

  __annotations__ = {}
  __firstlineno__ = 119
  __init__(aggregation)
    Parameters:

      aggregation (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.aggregates'
  __static_attributes__ = ('datatype', 'value')
  get_value()
    Return type:

      `Literal`

  update(row, aggregator)
    Parameters:

      - row (`FrozenBindings`)

      - aggregator (`Aggregator`)

    Return type:

      `None`

rdflib.plugins.sparql.aggregates.type_safe_numbers(*args)
  Parameters:

    args (`Union`[`Decimal`, `float`, `int`])

  Return type:

    `Iterable`[`Union`[`float`, `int`]]

## rdflib.plugins.sparql.algebra module

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

http://www.w3.org/TR/sparql11-query/#sparqlQuery

rdflib.plugins.sparql.algebra.BGP(triples=None)
  Parameters:

    triples (`Optional`[`List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]]])

  Return type:

    `CompValue`

exception rdflib.plugins.sparql.algebra.ExpressionNotCoveredException

  Bases: `Exception`

  __firstlineno__ = 953
  __module__ = 'rdflib.plugins.sparql.algebra'
  __static_attributes__ = ()
  __weakref__

    list of weak references to the object

rdflib.plugins.sparql.algebra.Extend(p, expr, var)
  Parameters:

    - p (`CompValue`)

    - expr (`Union`[`Identifier`, `Expr`])

    - var (`Variable`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Filter(expr, p)
  Parameters:

    - expr (`Expr`)

    - p (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Graph(term, graph)
  Parameters:

    - term (`Identifier`)

    - graph (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Group(p, expr=None)
  Parameters:

    - p (`CompValue`)

    - expr (`Optional`[`List`[`Variable`]])

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Join(p1, p2)
  Parameters:

    - p1 (`CompValue`)

    - p2 (`Optional`[`CompValue`])

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.LeftJoin(p1, p2, expr)
  Parameters:

    - p1 (`CompValue`)

    - p2 (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Minus(p1, p2)
  Parameters:

    - p1 (`CompValue`)

    - p2 (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.OrderBy(p, expr)
  Parameters:

    - p (`CompValue`)

    - expr (`List`[`CompValue`])

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Project(p, PV)
  Parameters:

    - p (`CompValue`)

    - PV (`List`[`Variable`])

  Return type:

    `CompValue`

exception rdflib.plugins.sparql.algebra.StopTraversal(rv)

  Bases: `Exception`

  Parameters:

    rv (`bool`)

  __firstlineno__ = 398
  __init__(rv)
    Parameters:

      rv (`bool`)

  __module__ = 'rdflib.plugins.sparql.algebra'
  __static_attributes__ = ('rv',)
  __weakref__

    list of weak references to the object

rdflib.plugins.sparql.algebra.ToMultiSet(p)
  Parameters:

    p (`Union`[`List`[`Dict`[`Variable`, `str`]], `CompValue`])

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Union(p1, p2)
  Parameters:

    - p1 (`CompValue`)

    - p2 (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.Values(res)
  Parameters:

    res (`List`[`Dict`[`Variable`, `str`]])

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.analyse(n, children)

  Some things can be lazily joined. This propegates whether they can up the tree and sets lazy flags for all joins

  Parameters:

    - n (`Any`)

    - children (`Any`)

  Return type:

    `bool`

rdflib.plugins.sparql.algebra.collectAndRemoveFilters(parts)

  FILTER expressions apply to the whole group graph pattern in which they appear.

  http://www.w3.org/TR/sparql11-query/#sparqlCollectFilters

  Parameters:

    parts (`List`[`CompValue`])

  Return type:

    `Optional`[`Expr`]

rdflib.plugins.sparql.algebra.pprintAlgebra(q)
  Return type:

    `None`

rdflib.plugins.sparql.algebra.reorderTriples(l_)

  Reorder triple patterns so that we execute the ones with most bindings first

  Parameters:

    l_ (`Iterable`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]])

  Return type:

    `List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]]

rdflib.plugins.sparql.algebra.simplify(n)

  Remove joins to empty BGPs

  Parameters:

    n (`Any`)

  Return type:

    `Optional`[`CompValue`]

rdflib.plugins.sparql.algebra.translate(q)

  http://www.w3.org/TR/sparql11-query/#convertSolMod

  Parameters:

    q (`CompValue`)

  Return type:

    `Tuple`[`Optional`[`CompValue`], `List`[`Variable`]]

rdflib.plugins.sparql.algebra.translateAggregates(q, M)
  Parameters:

    - q (`CompValue`)

    - M (`CompValue`)

  Return type:

    `Tuple`[`CompValue`, `List`[`Tuple`[`Variable`, `Variable`]]]

rdflib.plugins.sparql.algebra.translateAlgebra(query_algebra)

  Translates a SPARQL 1.1 algebra tree into the corresponding query string.

  Parameters:

    query_algebra (`Query`) – An algebra returned by `translateQuery`.

  Return type:

    `str`

  Returns:

    The query form generated from the SPARQL 1.1 algebra tree for SELECT queries.

rdflib.plugins.sparql.algebra.translateExists(e)

  Translate the graph pattern used by EXISTS and NOT EXISTS http://www.w3.org/TR/sparql11-query/#sparqlCollectFilters

  Parameters:

    e (`Union`[`Expr`, `Literal`, `Variable`, `URIRef`])

  Return type:

    `Union`[`Expr`, `Literal`, `Variable`, `URIRef`]

rdflib.plugins.sparql.algebra.translateGraphGraphPattern(graphPattern)
  Parameters:

    graphPattern (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.translateGroupGraphPattern(graphPattern)

  http://www.w3.org/TR/sparql11-query/#convertGraphPattern

  Parameters:

    graphPattern (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.translateGroupOrUnionGraphPattern(graphPattern)
  Parameters:

    graphPattern (`CompValue`)

  Return type:

    `Optional`[`CompValue`]

rdflib.plugins.sparql.algebra.translateInlineData(graphPattern)
  Parameters:

    graphPattern (`CompValue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.translatePName(p, prologue)

  Expand prefixed/relative URIs

  Parameters:

    - p (`Union`[`CompValue`, `str`])

    - prologue (`Prologue`)

  Return type:

    `Optional`[`Identifier`]

rdflib.plugins.sparql.algebra.translatePath(p)

  Translate PropertyPath expressions

  Parameters:

    p (`Union`[`CompValue`, `URIRef`])

  Return type:

    `Optional`[`Path`]

rdflib.plugins.sparql.algebra.translatePrologue(p, base, initNs=None, prologue=None)
  Parameters:

    - p (`ParseResults`)

    - base (`Optional`[`str`])

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - prologue (`Optional`[`Prologue`])

  Return type:

    `Prologue`

rdflib.plugins.sparql.algebra.translateQuads(quads)
  Parameters:

    quads (`CompValue`)

  Return type:

    `Tuple`[`List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]], `DefaultDict`[`str`, `List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]]]]

rdflib.plugins.sparql.algebra.translateQuery(q, base=None, initNs=None)

  Translate a query-parsetree to a SPARQL Algebra Expression

  Return a rdflib.plugins.sparql.sparql.Query object

  Parameters:

    - q (`ParseResults`)

    - base (`Optional`[`str`])

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

  Return type:

    `Query`

rdflib.plugins.sparql.algebra.translateUpdate(q, base=None, initNs=None)

  Returns a list of SPARQL Update Algebra expressions

  Parameters:

    - q (`CompValue`)

    - base (`Optional`[`str`])

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

  Return type:

    `Update`

rdflib.plugins.sparql.algebra.translateUpdate1(u, prologue)
  Parameters:

    - u (`CompValue`)

    - prologue (`Prologue`)

  Return type:

    `CompValue`

rdflib.plugins.sparql.algebra.translateValues(v)
  Parameters:

    v (`CompValue`)

  Return type:

    `Union`[`List`[`Dict`[`Variable`, `str`]], `CompValue`]

rdflib.plugins.sparql.algebra.traverse(tree, visitPre=lambda n: ..., visitPost=lambda n: ..., complete=None)

  Traverse tree, visit each node with visit function visit function may raise StopTraversal to stop traversal if complete!=None, it is returned on complete traversal, otherwise the transformed tree is returned

  Parameters:

    - visitPre (`Callable`[[`Any`], `Any`])

    - visitPost (`Callable`[[`Any`], `Any`])

    - complete (`Optional`[`bool`])

  Return type:

    `Any`

rdflib.plugins.sparql.algebra.triples(l)
  Parameters:

    l (`Union`[`List`[`List`[`Identifier`]], `List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]]])

  Return type:

    `List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]]

## rdflib.plugins.sparql.datatypes module

Utility functions for supporting the XML Schema Datatypes hierarchy

rdflib.plugins.sparql.datatypes.type_promotion(t1, t2)
  Parameters:

    - t1 (`URIRef`)

    - t2 (`Optional`[`URIRef`])

  Return type:

    `URIRef`

## rdflib.plugins.sparql.evaluate module

These method recursively evaluate the SPARQL Algebra

evalQuery is the entry-point, it will setup context and return the SPARQLResult object

evalPart is called on each level and will delegate to the right method

A rdflib.plugins.sparql.sparql.QueryContext is passed along, keeping information needed for evaluation

A list of dicts (solution mappings) is returned, apart from GroupBy which may also return a dict of list of dicts

rdflib.plugins.sparql.evaluate.evalAggregateJoin(ctx, agg)
  Parameters:

    - ctx (`QueryContext`)

    - agg (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalAskQuery(ctx, query)
  Parameters:

    - ctx (`QueryContext`)

    - query (`CompValue`)

  Return type:

    `Mapping`[`str`, `Union`[`str`, `bool`]]

rdflib.plugins.sparql.evaluate.evalBGP(ctx, bgp)

  A basic graph pattern

  Parameters:

    - ctx (`QueryContext`)

    - bgp (`List`[`Tuple`[`Identifier`, `Identifier`, `Identifier`]])

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalConstructQuery(ctx, query)
  Parameters:

    - ctx (`QueryContext`)

    - query (`CompValue`)

  Return type:

    `Mapping`[`str`, `Union`[`str`, `Graph`]]

rdflib.plugins.sparql.evaluate.evalDescribeQuery(ctx, query)
  Parameters:

    ctx (`QueryContext`)

  Return type:

    `Dict`[`str`, `Union`[`str`, `Graph`]]

rdflib.plugins.sparql.evaluate.evalDistinct(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalExtend(ctx, extend)
  Parameters:

    - ctx (`QueryContext`)

    - extend (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalFilter(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalGraph(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalGroup(ctx, group)

  http://www.w3.org/TR/sparql11-query/#defn_algGroup

  Parameters:

    - ctx (`QueryContext`)

    - group (`CompValue`)

rdflib.plugins.sparql.evaluate.evalJoin(ctx, join)
  Parameters:

    - ctx (`QueryContext`)

    - join (`CompValue`)

  Return type:

    `Generator`[`FrozenDict`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalLazyJoin(ctx, join)

  A lazy join will push the variables bound in the first part to the second part, essentially doing the join implicitly hopefully evaluating much fewer triples

  Parameters:

    - ctx (`QueryContext`)

    - join (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalLeftJoin(ctx, join)
  Parameters:

    - ctx (`QueryContext`)

    - join (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalMinus(ctx, minus)
  Parameters:

    - ctx (`QueryContext`)

    - minus (`CompValue`)

  Return type:

    `Generator`[`FrozenDict`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalMultiset(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

rdflib.plugins.sparql.evaluate.evalOrderBy(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalPart(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Any`

rdflib.plugins.sparql.evaluate.evalProject(ctx, project)
  Parameters:

    - ctx (`QueryContext`)

    - project (`CompValue`)

rdflib.plugins.sparql.evaluate.evalQuery(graph, query, initBindings=None, base=None)

  Caution

  This method can access indirectly requested network endpoints, for example, query processing will attempt to access network endpoints specified in `SERVICE` directives.

  When processing untrusted or potentially malicious queries, measures should be taken to restrict network and file access.

  For information on available security measures, see the RDFLib Security Considerations documentation.

  Parameters:

    - graph (`Graph`)

    - query (`Query`)

    - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

    - base (`Optional`[`str`])

  Return type:

    `Mapping`[`Any`, `Any`]

rdflib.plugins.sparql.evaluate.evalReduced(ctx, part)

  apply REDUCED to result

  REDUCED is not as strict as DISTINCT, but if the incoming rows were sorted it should produce the same result with limited extra memory and time per incoming row.

  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

rdflib.plugins.sparql.evaluate.evalSelectQuery(ctx, query)
  Parameters:

    - ctx (`QueryContext`)

    - query (`CompValue`)

  Return type:

    `Mapping`[`str`, `Union`[`str`, `List`[`Variable`], `Iterable`[`FrozenDict`]]]

rdflib.plugins.sparql.evaluate.evalServiceQuery(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

rdflib.plugins.sparql.evaluate.evalSlice(ctx, slice)
  Parameters:

    - ctx (`QueryContext`)

    - slice (`CompValue`)

rdflib.plugins.sparql.evaluate.evalUnion(ctx, union)
  Parameters:

    - ctx (`QueryContext`)

    - union (`CompValue`)

  Return type:

    `List`[`Any`]

rdflib.plugins.sparql.evaluate.evalValues(ctx, part)
  Parameters:

    - ctx (`QueryContext`)

    - part (`CompValue`)

  Return type:

    `Generator`[`FrozenBindings`, `None`, `None`]

## rdflib.plugins.sparql.evalutils module

## rdflib.plugins.sparql.operators module

This contains evaluation functions for expressions

They get bound as instances-methods to the CompValue objects from parserutils using setEvalFn

rdflib.plugins.sparql.operators.AdditiveExpression(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`Union`[`QueryContext`, `FrozenBindings`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_ABS(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-abs

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_BNODE(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-bnode

  Return type:

    `BNode`

rdflib.plugins.sparql.operators.Builtin_BOUND(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-bound

  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_CEIL(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-ceil

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_COALESCE(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-coalesce

  Parameters:

    expr (`Expr`)

rdflib.plugins.sparql.operators.Builtin_CONCAT(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-concat

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_CONTAINS(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strcontains

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_DATATYPE(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Optional`[`str`]

rdflib.plugins.sparql.operators.Builtin_DAY(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_ENCODE_FOR_URI(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_EXISTS(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_FLOOR(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-floor

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_HOURS(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_IF(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-if

  Parameters:

    expr (`Expr`)

rdflib.plugins.sparql.operators.Builtin_IRI(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-iri

  Parameters:

    - expr (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `URIRef`

rdflib.plugins.sparql.operators.Builtin_LANG(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-lang

  Returns the language tag of ltrl, if it has one. It returns “” if ltrl has no language tag. Note that the RDF data model does not include literals with an empty language tag.

  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_LANGMATCHES(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-langMatches

  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_LCASE(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_MD5(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_MINUTES(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_MONTH(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_NOW(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-now

  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_RAND(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#idp2133952

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_REGEX(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-regex Invokes the XPath fn:matches function to match text against a regular expression pattern. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section 7.6.1 Regular Expression Syntax

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_REPLACE(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-substr

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_ROUND(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-round

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SECONDS(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-seconds

  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SHA1(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SHA256(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SHA384(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SHA512(expr, ctx)
  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STR(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRAFTER(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strafter

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRBEFORE(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strbefore

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRDT(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strdt

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRENDS(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strends

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRLANG(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strlang

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRLEN(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRSTARTS(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strstarts

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_STRUUID(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strdt

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_SUBSTR(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-substr

  Parameters:

    expr (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_TIMEZONE(e, ctx)

  http://www.w3.org/TR/sparql11-query/#func-timezone

  Return type:

    `Literal`

  Returns:

    the timezone part of arg as an xsd:dayTimeDuration.

  Raises:

    an error if there is no timezone.

  Parameters:

    e (`Expr`)

rdflib.plugins.sparql.operators.Builtin_TZ(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_UCASE(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_UUID(expr, ctx)

  http://www.w3.org/TR/sparql11-query/#func-strdt

  Parameters:

    expr (`Expr`)

  Return type:

    `URIRef`

rdflib.plugins.sparql.operators.Builtin_YEAR(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_isBLANK(expr, ctx)
  Parameters:

    - expr (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_isIRI(expr, ctx)
  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_isLITERAL(expr, ctx)
  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_isNUMERIC(expr, ctx)
  Return type:

    `Literal`

rdflib.plugins.sparql.operators.Builtin_sameTerm(e, ctx)
  Parameters:

    e (`Expr`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.ConditionalAndExpression(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`Union`[`QueryContext`, `FrozenBindings`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.ConditionalOrExpression(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`Union`[`QueryContext`, `FrozenBindings`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.EBV(rt)

  Effective Boolean Value (EBV)

  - If the argument is a typed literal with a datatype of xsd:boolean, the EBV is the value of that argument.

  - If the argument is a plain literal or a typed literal with a datatype of xsd:string, the EBV is false if the operand value has zero length; otherwise the EBV is true.

  - If the argument is a numeric type or a typed literal with a datatype derived from a numeric type, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.

  - All other arguments, including unbound arguments, produce a type error.

  Parameters:

    rt (`Union`[`Identifier`, `SPARQLError`, `Expr`])

  Return type:

    `bool`

rdflib.plugins.sparql.operators.Function(e, ctx)

  Custom functions and casts

  Parameters:

    - e (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Node`

rdflib.plugins.sparql.operators.MultiplicativeExpression(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`Union`[`QueryContext`, `FrozenBindings`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.RelationalExpression(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`Union`[`QueryContext`, `FrozenBindings`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.UnaryMinus(expr, ctx)
  Parameters:

    - expr (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.UnaryNot(expr, ctx)
  Parameters:

    - expr (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.UnaryPlus(expr, ctx)
  Parameters:

    - expr (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.and_(*args)
  Parameters:

    args (`Expr`)

  Return type:

    `Expr`

rdflib.plugins.sparql.operators.calculateDuration(obj1, obj2)

  returns the duration Literal between two datetime

  Parameters:

    - obj1 (`Union`[`date`, `datetime`])

    - obj2 (`Union`[`date`, `datetime`])

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.calculateFinalDateTime(obj1, dt1, obj2, dt2, operation)

  Calculates the final dateTime/date/time resultant after addition/ subtraction of duration/dayTimeDuration/yearMonthDuration

  Parameters:

    - obj1 (`Union`[`date`, `datetime`])

    - dt1 (`URIRef`)

    - obj2 (`Union`[`Duration`, `timedelta`])

    - dt2 (`URIRef`)

    - operation (`str`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.custom_function(uri, override=False, raw=False)

  Decorator version of `register_custom_function()`.

  Parameters:

    - uri (`URIRef`)

    - override (`bool`)

    - raw (`bool`)

  Return type:

    `Callable`[[`Callable`[[`Expr`, `FrozenBindings`], `Node`]], `Callable`[[`Expr`, `FrozenBindings`], `Node`]]

rdflib.plugins.sparql.operators.date(e)
  Parameters:

    e (`Literal`)

  Return type:

    `date`

rdflib.plugins.sparql.operators.dateTimeObjects(expr)

  return a dataTime/date/time/duration/dayTimeDuration/yearMonthDuration python objects from a literal

  Parameters:

    expr (`Literal`)

  Return type:

    `Any`

rdflib.plugins.sparql.operators.datetime(e)
  Parameters:

    e (`Literal`)

  Return type:

    `datetime`

rdflib.plugins.sparql.operators.default_cast(e, ctx)
  Parameters:

    - e (`Expr`)

    - ctx (`FrozenBindings`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.isCompatibleDateTimeDatatype(obj1, dt1, obj2, dt2)

  Returns a boolean indicating if first object is compatible with operation(+/-) over second object.

  Parameters:

    - obj1 (`Union`[`date`, `datetime`])

    - dt1 (`URIRef`)

    - obj2 (`Union`[`Duration`, `timedelta`])

    - dt2 (`URIRef`)

  Return type:

    `bool`

rdflib.plugins.sparql.operators.literal(s)
  Parameters:

    s (`Literal`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.not_(arg)
  Return type:

    `Expr`

rdflib.plugins.sparql.operators.numeric(expr)

  return a number from a literal http://www.w3.org/TR/xpath20/#promotion

  or TypeError

  Parameters:

    expr (`Literal`)

  Return type:

    `Any`

rdflib.plugins.sparql.operators.parse_datetime(object, /)

  string -> datetime from a string in most ISO 8601 formats

rdflib.plugins.sparql.operators.register_custom_function(uri, func, override=False, raw=False)

  Register a custom SPARQL function.

  By default, the function will be passed the RDF terms in the argument list. If raw is True, the function will be passed an Expression and a Context.

  The function must return an RDF term, or raise a SparqlError.

  Parameters:

    - uri (`URIRef`)

    - func (`Callable`[[`Expr`, `FrozenBindings`], `Node`])

    - override (`bool`)

    - raw (`bool`)

  Return type:

    `None`

rdflib.plugins.sparql.operators.simplify(expr)
  Parameters:

    expr (`Any`)

  Return type:

    `Any`

rdflib.plugins.sparql.operators.string(s)

  Make sure the passed thing is a string literal i.e. plain literal, xsd:string literal or lang-tagged literal

  Parameters:

    s (`Literal`)

  Return type:

    `Literal`

rdflib.plugins.sparql.operators.unregister_custom_function(uri, func=None)

  The ‘func’ argument is included for compatibility with existing code. A previous implementation checked that the function associated with the given uri was actually ‘func’, but this is not necessary as the uri should uniquely identify the function.

  Parameters:

    - uri (`URIRef`)

    - func (`Optional`[`Callable`[`...`, `Any`]])

  Return type:

    `None`

## rdflib.plugins.sparql.parser module

SPARQL 1.1 Parser

based on pyparsing

rdflib.plugins.sparql.parser.expandBNodeTriples(terms)

  expand [ ?p ?o ] syntax for implicit bnodes

  Parameters:

    terms (`ParseResults`)

  Return type:

    `List`[`Any`]

rdflib.plugins.sparql.parser.expandCollection(terms)

  expand ( 1 2 3 ) notation for collections

  Parameters:

    terms (`ParseResults`)

  Return type:

    `List`[`List`[`Any`]]

rdflib.plugins.sparql.parser.expandTriples(terms)

  Expand ; and , syntax for repeat predicates, subjects

  Parameters:

    terms (`ParseResults`)

  Return type:

    `List`[`Any`]

rdflib.plugins.sparql.parser.expandUnicodeEscapes(q)

  The syntax of the SPARQL Query Language is expressed over code points in Unicode [UNICODE]. The encoding is always UTF-8 [RFC3629]. Unicode code points may also be expressed using an uXXXX (U+0 to U+FFFF) or UXXXXXXXX syntax (for U+10000 onwards) where X is a hexadecimal digit [0-9A-F]

  Parameters:

    q (`str`)

  Return type:

    `str`

rdflib.plugins.sparql.parser.neg(literal)
  Parameters:

    literal (`Literal`)

  Return type:

    `Literal`

rdflib.plugins.sparql.parser.parseQuery(q)
  Parameters:

    q (`Union`[`str`, `bytes`, `TextIO`, `BinaryIO`])

  Return type:

    `ParseResults`

rdflib.plugins.sparql.parser.parseUpdate(q)
  Parameters:

    q (`Union`[`str`, `bytes`, `TextIO`, `BinaryIO`])

  Return type:

    `CompValue`

rdflib.plugins.sparql.parser.setDataType(terms)
  Parameters:

    terms (`Tuple`[`Any`, `Optional`[`str`]])

  Return type:

    `Literal`

rdflib.plugins.sparql.parser.setLanguage(terms)
  Parameters:

    terms (`Tuple`[`Any`, `Optional`[`str`]])

  Return type:

    `Literal`

## rdflib.plugins.sparql.parserutils module

NOTE: PyParsing setResultName/__call__ provides a very similar solution to this I didn’t realise at the time of writing and I will remove a lot of this code at some point

Utility classes for creating an abstract-syntax tree out with pyparsing actions

Lets you label and group parts of parser production rules

For example:

# [5] BaseDecl ::= ‘BASE’ IRIREF BaseDecl = Comp(‘Base’, Keyword(‘BASE’) + Param(‘iri’,IRIREF))

After parsing, this gives you back an CompValue object, which is a dict/object with the parameters specified. So you can access the parameters are attributes or as keys:

baseDecl.iri

Comp lets you set an evalFn that is bound to the eval method of the resulting CompValue

class rdflib.plugins.sparql.parserutils.Comp(name, expr)

  Bases: `TokenConverter`

  A pyparsing token for grouping together things with a label Any sub-tokens that are not Params will be ignored.

  Returns CompValue / Expr objects - depending on whether evalFn is set.

  Parameters:

    - name (`str`)

    - expr (`ParserElement`)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'DEFAULT_WHITE_CHARS': 'str', '_defaultName': 'typing.Optional[str]', '_literalStringClass': 'type', 'customName': 'str', 'evalfn': 'Optional[Callable[[Any, Any], Any]]', 'failAction': 'typing.Optional[ParseFailAction]', 'ignoreExprs': "List['ParserElement']", 'parseAction': 'List[ParseAction]', 'recursion_memos': "typing.Dict[Tuple[int, 'Forward', bool], Tuple[int, Union[ParseResults, Exception]]]", 'resultsName': 'str', 'suppress_warnings_': 'List[Diagnostics]', 'verbose_stacktrace': 'bool'}
  __firstlineno__ = 233
  __init__(name, expr)
    Parameters:

      - name (`str`)

      - expr (`ParserElement`)

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __slotnames__ = []
  __static_attributes__ = ('evalfn', 'expr')
  postParse(instring, loc, tokenList)
    Parameters:

      - instring (`str`)

      - loc (`int`)

      - tokenList (`ParseResults`)

    Return type:

      `Union`[`Expr`, `CompValue`]

  setEvalFn(evalfn)
    Parameters:

      evalfn (`Callable`[[`Any`, `Any`], `Any`])

    Return type:

      `Comp`

class rdflib.plugins.sparql.parserutils.CompValue(name, **values)

  Bases: `OrderedDict`

  The result of parsing a Comp Any included Params are available as Dict keys or as attributes

  Parameters:

    name (`str`)

  __firstlineno__ = 152
  __getattr__(a)
    Parameters:

      a (`str`)

    Return type:

      `Any`

  __getitem__(a)

    Return self[key].

  __init__(name, **values)
    Parameters:

      name (`str`)

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __repr__()

    Return repr(self).

    Return type:

      `str`

  __static_attributes__ = ('name',)
  __str__()

    Return str(self).

    Return type:

      `str`

  clone()
    Return type:

      `CompValue`

  get(a, variables=False, errors=False)

    Return the value for key if key is in the dictionary, else default.

    Parameters:

      - variables (`bool`)

      - errors (`bool`)

class rdflib.plugins.sparql.parserutils.Expr(name, evalfn=None, **values)

  Bases: `CompValue`

  A CompValue that is evaluatable

  Parameters:

    - name (`str`)

    - evalfn (`Optional`[`Callable`[[`Any`, `Any`], `Any`]])

  __annotations__ = {}
  __firstlineno__ = 205
  __init__(name, evalfn=None, **values)
    Parameters:

      - name (`str`)

      - evalfn (`Optional`[`Callable`[[`Any`, `Any`], `Any`]])

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __static_attributes__ = ('_evalfn', 'ctx')
  eval(ctx={})
    Parameters:

      ctx (`Any`)

    Return type:

      `Union`[`SPARQLError`, `Any`]

class rdflib.plugins.sparql.parserutils.Param(name, expr, isList=False)

  Bases: `TokenConverter`

  A pyparsing token for labelling a part of the parse-tree if isList is true repeat occurrences of ParamList have their values merged in a list

  Parameters:

    - name (`str`)

    - isList (`bool`)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'DEFAULT_WHITE_CHARS': 'str', '_defaultName': 'typing.Optional[str]', '_literalStringClass': 'type', 'customName': 'str', 'failAction': 'typing.Optional[ParseFailAction]', 'ignoreExprs': "List['ParserElement']", 'parseAction': 'List[ParseAction]', 'recursion_memos': "typing.Dict[Tuple[int, 'Forward', bool], Tuple[int, Union[ParseResults, Exception]]]", 'resultsName': 'str', 'suppress_warnings_': 'List[Diagnostics]', 'verbose_stacktrace': 'bool'}
  __firstlineno__ = 123
  __init__(name, expr, isList=False)
    Parameters:

      - name (`str`)

      - isList (`bool`)

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __slotnames__ = []
  __static_attributes__ = ('isList',)
  postParse2(tokenList)
    Parameters:

      tokenList (`Union`[`List`[`Any`], `ParseResults`])

    Return type:

      `ParamValue`

class rdflib.plugins.sparql.parserutils.ParamList(name, expr)

  Bases: `Param`

  A shortcut for a Param with isList=True

  Parameters:

    name (`str`)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'DEFAULT_WHITE_CHARS': 'str', '_defaultName': 'typing.Optional[str]', '_literalStringClass': 'type', 'customName': 'str', 'failAction': 'typing.Optional[ParseFailAction]', 'ignoreExprs': "List['ParserElement']", 'parseAction': 'List[ParseAction]', 'recursion_memos': "typing.Dict[Tuple[int, 'Forward', bool], Tuple[int, Union[ParseResults, Exception]]]", 'resultsName': 'str', 'suppress_warnings_': 'List[Diagnostics]', 'verbose_stacktrace': 'bool'}
  __firstlineno__ = 140
  __init__(name, expr)
    Parameters:

      name (`str`)

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __static_attributes__ = ()

class rdflib.plugins.sparql.parserutils.ParamValue(name, tokenList, isList)

  Bases: `object`

  The result of parsing a Param This just keeps the name/value All cleverness is in the CompValue

  Parameters:

    - name (`str`)

    - tokenList (`Union`[`List`[`Any`], `ParseResults`])

    - isList (`bool`)

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.parserutils', '__firstlineno__': 102, '__doc__': '\nThe result of parsing a Param\nThis just keeps the name/value\nAll cleverness is in the CompValue\n', '__init__': <function ParamValue.__init__>, '__str__': <function ParamValue.__str__>, '__static_attributes__': ('isList', 'name', 'tokenList'), '__dict__': <attribute '__dict__' of 'ParamValue' objects>, '__weakref__': <attribute '__weakref__' of 'ParamValue' objects>, '__annotations__': {}})
  __firstlineno__ = 102
  __init__(name, tokenList, isList)
    Parameters:

      - name (`str`)

      - tokenList (`Union`[`List`[`Any`], `ParseResults`])

      - isList (`bool`)

  __module__ = 'rdflib.plugins.sparql.parserutils'
  __static_attributes__ = ('isList', 'name', 'tokenList')
  __str__()

    Return str(self).

    Return type:

      `str`

  __weakref__

    list of weak references to the object

rdflib.plugins.sparql.parserutils.prettify_parsetree(t, indent='', depth=0)
  Parameters:

    - t (`ParseResults`)

    - indent (`str`)

    - depth (`int`)

  Return type:

    `str`

rdflib.plugins.sparql.parserutils.value(ctx, val, variables=False, errors=False)

  utility function for evaluating something…

  Variables will be looked up in the context Normally, non-bound vars is an error, set variables=True to return unbound vars

  Normally, an error raises the error, set errors=True to return error

  Parameters:

    - ctx (`FrozenBindings`)

    - val (`Any`)

    - variables (`bool`)

    - errors (`bool`)

  Return type:

    `Any`

## rdflib.plugins.sparql.processor module

Code for tying SPARQL Engine into RDFLib

These should be automatically registered with RDFLib

class rdflib.plugins.sparql.processor.SPARQLProcessor(graph)

  Bases: `Processor`

  __annotations__ = {}
  __firstlineno__ = 109
  __init__(graph)
  __module__ = 'rdflib.plugins.sparql.processor'
  __static_attributes__ = ('graph',)
  query(strOrQuery, initBindings=None, initNs=None, base=None, DEBUG=False)

    Evaluate a query with the given initial bindings, and initial namespaces. The given base is used to resolve relative URIs in the query and will be overridden by any BASE given in the query.

    Caution

    This method can access indirectly requested network endpoints, for example, query processing will attempt to access network endpoints specified in `SERVICE` directives.

    When processing untrusted or potentially malicious queries, measures should be taken to restrict network and file access.

    For information on available security measures, see the RDFLib Security Considerations documentation.

    Parameters:

      - strOrQuery (`Union`[`str`, `Query`])

      - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

      - initNs (`Optional`[`Mapping`[`str`, `Any`]])

      - base (`Optional`[`str`])

      - DEBUG (`bool`)

    Return type:

      `Mapping`[`str`, `Any`]

class rdflib.plugins.sparql.processor.SPARQLResult(res)

  Bases: `Result`

  Parameters:

    res (`Mapping`[`str`, `Any`])

  __annotations__ = {}
  __firstlineno__ = 68
  __init__(res)
    Parameters:

      res (`Mapping`[`str`, `Any`])

  __module__ = 'rdflib.plugins.sparql.processor'
  __static_attributes__ = ('askAnswer', 'bindings', 'graph', 'vars')

class rdflib.plugins.sparql.processor.SPARQLUpdateProcessor(graph)

  Bases: `UpdateProcessor`

  __annotations__ = {}
  __firstlineno__ = 78
  __init__(graph)
  __module__ = 'rdflib.plugins.sparql.processor'
  __static_attributes__ = ('graph',)
  update(strOrQuery, initBindings=None, initNs=None)

    Caution

    This method can access indirectly requested network endpoints, for example, query processing will attempt to access network endpoints specified in `SERVICE` directives.

    When processing untrusted or potentially malicious queries, measures should be taken to restrict network and file access.

    For information on available security measures, see the RDFLib Security Considerations documentation.

    Parameters:

      - strOrQuery (`Union`[`str`, `Update`])

      - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

      - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    Return type:

      `None`

rdflib.plugins.sparql.processor.prepareQuery(queryString, initNs=None, base=None)

  Parse and translate a SPARQL Query

  Parameters:

    - queryString (`str`)

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `Query`

rdflib.plugins.sparql.processor.prepareUpdate(updateString, initNs=None, base=None)

  Parse and translate a SPARQL Update

  Parameters:

    - updateString (`str`)

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `Update`

rdflib.plugins.sparql.processor.processUpdate(graph, updateString, initBindings=None, initNs=None, base=None)

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

  Parameters:

    - graph (`Graph`)

    - updateString (`str`)

    - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `None`

## rdflib.plugins.sparql.sparql module

exception rdflib.plugins.sparql.sparql.AlreadyBound

  Bases: `SPARQLError`

  Raised when trying to bind a variable that is already bound!

  __firstlineno__ = 45
  __init__()
  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ()

class rdflib.plugins.sparql.sparql.Bindings(outer=None, d=[])

  Bases: `MutableMapping`

  A single level of a stack of variable-value bindings. Each dict keeps a reference to the dict below it, any failed lookup is propegated back

  In python 3.3 this could be a collections.ChainMap

  Parameters:

    outer (`Optional`[`Bindings`])

  __abstractmethods__ = frozenset({})
  __contains__(key)
    Parameters:

      key (`Any`)

    Return type:

      `bool`

  __delitem__(key)
    Parameters:

      key (`str`)

    Return type:

      `None`

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 57, '__doc__': '\n\nA single level of a stack of variable-value bindings.\nEach dict keeps a reference to the dict below it,\nany failed lookup is propegated back\n\nIn python 3.3 this could be a collections.ChainMap\n', '__init__': <function Bindings.__init__>, '__getitem__': <function Bindings.__getitem__>, '__contains__': <function Bindings.__contains__>, '__setitem__': <function Bindings.__setitem__>, '__delitem__': <function Bindings.__delitem__>, '__len__': <function Bindings.__len__>, '__iter__': <function Bindings.__iter__>, '__str__': <function Bindings.__str__>, '__repr__': <function Bindings.__repr__>, '__static_attributes__': ('_d', 'outer'), '__dict__': <attribute '__dict__' of 'Bindings' objects>, '__weakref__': <attribute '__weakref__' of 'Bindings' objects>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_d': 'Dict[str, str]'}})
  __firstlineno__ = 57
  __getitem__(key)
    Parameters:

      key (`str`)

    Return type:

      `str`

  __init__(outer=None, d=[])
    Parameters:

      outer (`Optional`[`Bindings`])

  __iter__()
    Return type:

      `Generator`[`str`, `None`, `None`]

  __len__()
    Return type:

      `int`

  __module__ = 'rdflib.plugins.sparql.sparql'
  __repr__()

    Return repr(self).

    Return type:

      `str`

  __setitem__(key, value)
    Parameters:

      - key (`str`)

      - value (`Any`)

    Return type:

      `None`

  __static_attributes__ = ('_d', 'outer')
  __str__()

    Return str(self).

    Return type:

      `str`

  __weakref__

    list of weak references to the object

class rdflib.plugins.sparql.sparql.FrozenBindings(ctx, *args, **kwargs)

  Bases: `FrozenDict`

  Parameters:

    ctx (`QueryContext`)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'_d': 'Dict[Identifier, Identifier]', '_hash': 'Optional[int]'}
  __firstlineno__ = 176
  __getitem__(key)
    Parameters:

      key (`Union`[`Identifier`, `str`])

    Return type:

      `Identifier`

  __init__(ctx, *args, **kwargs)
    Parameters:

      ctx (`QueryContext`)

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ('ctx',)
  property bnodes: Mapping[Identifier, BNode]
  forget(before, _except=None)

    return a frozen dict only of bindings made in self since before

    Parameters:

      - before (`QueryContext`)

      - _except (`Optional`[`Container`[`Variable`]])

    Return type:

      `FrozenBindings`

  merge(other)
    Parameters:

      other (`Mapping`[`Identifier`, `Identifier`])

    Return type:

      `FrozenBindings`

  property now: datetime
  project(vars)
    Parameters:

      vars (`Container`[`Variable`])

    Return type:

      `FrozenBindings`

  property prologue: Prologue | None
  remember(these)

    return a frozen dict only of bindings in these

    Return type:

      `FrozenBindings`

class rdflib.plugins.sparql.sparql.FrozenDict(*args, **kwargs)

  Bases: `Mapping`

  An immutable hashable dict

  Taken from http://stackoverflow.com/a/2704866/81121

  Parameters:

    - args (`Any`)

    - kwargs (`Any`)

  __abstractmethods__ = frozenset({})
  __annotations__ = {'_d': 'Dict[Identifier, Identifier]', '_hash': 'Optional[int]'}
  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 114, '__doc__': '\nAn immutable hashable dict\n\nTaken from http://stackoverflow.com/a/2704866/81121\n\n', '__init__': <function FrozenDict.__init__>, '__iter__': <function FrozenDict.__iter__>, '__len__': <function FrozenDict.__len__>, '__getitem__': <function FrozenDict.__getitem__>, '__hash__': <function FrozenDict.__hash__>, 'project': <function FrozenDict.project>, 'disjointDomain': <function FrozenDict.disjointDomain>, 'compatible': <function FrozenDict.compatible>, 'merge': <function FrozenDict.merge>, '__str__': <function FrozenDict.__str__>, '__repr__': <function FrozenDict.__repr__>, '__static_attributes__': ('_d', '_hash'), '__dict__': <attribute '__dict__' of 'FrozenDict' objects>, '__weakref__': <attribute '__weakref__' of 'FrozenDict' objects>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_d': 'Dict[Identifier, Identifier]', '_hash': 'Optional[int]'}})
  __firstlineno__ = 114
  __getitem__(key)
    Parameters:

      key (`Identifier`)

    Return type:

      `Identifier`

  __hash__()

    Return hash(self).

    Return type:

      `int`

  __init__(*args, **kwargs)
    Parameters:

      - args (`Any`)

      - kwargs (`Any`)

  __iter__()
  __len__()
    Return type:

      `int`

  __module__ = 'rdflib.plugins.sparql.sparql'
  __repr__()

    Return repr(self).

    Return type:

      `str`

  __static_attributes__ = ('_d', '_hash')
  __str__()

    Return str(self).

    Return type:

      `str`

  __weakref__

    list of weak references to the object

  compatible(other)
    Parameters:

      other (`Mapping`[`Identifier`, `Identifier`])

    Return type:

      `bool`

  disjointDomain(other)
    Parameters:

      other (`Mapping`[`Identifier`, `Identifier`])

    Return type:

      `bool`

  merge(other)
    Parameters:

      other (`Mapping`[`Identifier`, `Identifier`])

    Return type:

      `FrozenDict`

  project(vars)
    Parameters:

      vars (`Container`[`Variable`])

    Return type:

      `FrozenDict`

exception rdflib.plugins.sparql.sparql.NotBoundError(msg=None)

  Bases: `SPARQLError`

  Parameters:

    msg (`Optional`[`str`])

  __annotations__ = {}
  __firstlineno__ = 40
  __init__(msg=None)
    Parameters:

      msg (`Optional`[`str`])

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ()

class rdflib.plugins.sparql.sparql.Prologue

  Bases: `object`

  A class for holding prefixing bindings and base URI information

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 438, '__doc__': '\nA class for holding prefixing bindings and base URI information\n', '__init__': <function Prologue.__init__>, 'resolvePName': <function Prologue.resolvePName>, 'bind': <function Prologue.bind>, 'absolutize': <function Prologue.absolutize>, '__static_attributes__': ('base', 'namespace_manager'), '__dict__': <attribute '__dict__' of 'Prologue' objects>, '__weakref__': <attribute '__weakref__' of 'Prologue' objects>, '__annotations__': {'base': 'Optional[str]'}})
  __firstlineno__ = 438
  __init__()
  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ('base', 'namespace_manager')
  __weakref__

    list of weak references to the object

  absolutize(iri)

    Apply BASE / PREFIXes to URIs (and to datatypes in Literals)

    TODO: Move resolving URIs to pre-processing

    Parameters:

      iri (`Union`[`CompValue`, `str`, `None`])

    Return type:

      `Union`[`CompValue`, `str`, `None`]

  bind(prefix, uri)
    Parameters:

      - prefix (`Optional`[`str`])

      - uri (`Any`)

    Return type:

      `None`

  resolvePName(prefix, localname)
    Parameters:

      - prefix (`Optional`[`str`])

      - localname (`Optional`[`str`])

    Return type:

      `URIRef`

class rdflib.plugins.sparql.sparql.Query(prologue, algebra)

  Bases: `object`

  A parsed and translated query

  Parameters:

    - prologue (`Prologue`)

    - algebra (`CompValue`)

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 480, '__doc__': '\nA parsed and translated query\n', '__init__': <function Query.__init__>, '__static_attributes__': ('algebra', 'prologue'), '__dict__': <attribute '__dict__' of 'Query' objects>, '__weakref__': <attribute '__weakref__' of 'Query' objects>, '__annotations__': {'_original_args': 'Tuple[str, Mapping[str, str], Optional[str]]'}})
  __firstlineno__ = 480
  __init__(prologue, algebra)
    Parameters:

      - prologue (`Prologue`)

      - algebra (`CompValue`)

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ('algebra', 'prologue')
  __weakref__

    list of weak references to the object

class rdflib.plugins.sparql.sparql.QueryContext(graph=None, bindings=None, initBindings=None, datasetClause=None)

  Bases: `object`

  Query context - passed along when evaluating the query

  Parameters:

    - graph (`Optional`[`Graph`])

    - bindings (`Union`[`Bindings`, `FrozenBindings`, `List`[`Any`], `None`])

    - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 246, '__doc__': '\nQuery context - passed along when evaluating the query\n', '__init__': <function QueryContext.__init__>, 'now': <property object>, 'clone': <function QueryContext.clone>, 'dataset': <property object>, 'load': <function QueryContext.load>, '__getitem__': <function QueryContext.__getitem__>, 'get': <function QueryContext.get>, 'solution': <function QueryContext.solution>, '__setitem__': <function QueryContext.__setitem__>, 'pushGraph': <function QueryContext.pushGraph>, 'push': <function QueryContext.push>, 'clean': <function QueryContext.clean>, 'thaw': <function QueryContext.thaw>, '__static_attributes__': ('_dataset', '_now', 'bindings', 'bnodes', 'graph', 'initBindings', 'prologue'), '__dict__': <attribute '__dict__' of 'QueryContext' objects>, '__weakref__': <attribute '__weakref__' of 'QueryContext' objects>, '__annotations__': {'graph': 'Optional[Graph]', '_dataset': 'Optional[Union[Dataset, ConjunctiveGraph]]', 'prologue': 'Optional[Prologue]', '_now': 'Optional[datetime.datetime]', 'bnodes': 't.MutableMapping[Identifier, BNode]'}})
  __firstlineno__ = 246
  __getitem__(key)
    Parameters:

      key (`Union`[`str`, `Path`])

    Return type:

      `Union`[`str`, `Path`, `None`]

  __init__(graph=None, bindings=None, initBindings=None, datasetClause=None)
    Parameters:

      - graph (`Optional`[`Graph`])

      - bindings (`Union`[`Bindings`, `FrozenBindings`, `List`[`Any`], `None`])

      - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

  __module__ = 'rdflib.plugins.sparql.sparql'
  __setitem__(key, value)
    Parameters:

      - key (`str`)

      - value (`str`)

    Return type:

      `None`

  __static_attributes__ = ('_dataset', '_now', 'bindings', 'bnodes', 'graph', 'initBindings', 'prologue')
  __weakref__

    list of weak references to the object

  clean()
    Return type:

      `QueryContext`

  clone(bindings=None)
    Parameters:

      bindings (`Union`[`Bindings`, `FrozenBindings`, `List`[`Any`], `None`])

    Return type:

      `QueryContext`

  property dataset: ConjunctiveGraph

    “current dataset

  get(key, default=None)
    Parameters:

      - key (`str`)

      - default (`Optional`[`Any`])

    Return type:

      `Any`

  load(source, default=False, into=None, **kwargs)

    Load data from the source into the query context’s.

    Parameters:

      - source (`URIRef`) – The source to load from.

      - default (`bool`) – If `True`, triples from the source will be added to the default graph, otherwise it will be loaded into a graph with `source` URI as its name.

      - into (`Optional`[`Identifier`]) – The name of the graph to load the data into. If `None`, the source URI will be used as as the name of the graph.

      - kwargs (`Any`) – Keyword arguments to pass to `rdflib.graph.Graph.parse()`.

    Return type:

      `None`

  property now: datetime
  push()
    Return type:

      `QueryContext`

  pushGraph(graph)
    Parameters:

      graph (`Optional`[`Graph`])

    Return type:

      `QueryContext`

  solution(vars=None)

    Return a static copy of the current variable bindings as dict

    Parameters:

      vars (`Optional`[`Iterable`[`Variable`]])

    Return type:

      `FrozenBindings`

  thaw(frozenbindings)

    Create a new read/write query context from the given solution

    Parameters:

      frozenbindings (`FrozenBindings`)

    Return type:

      `QueryContext`

exception rdflib.plugins.sparql.sparql.SPARQLError(msg=None)

  Bases: `Exception`

  Parameters:

    msg (`Optional`[`str`])

  __annotations__ = {}
  __firstlineno__ = 35
  __init__(msg=None)
    Parameters:

      msg (`Optional`[`str`])

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ()
  __weakref__

    list of weak references to the object

exception rdflib.plugins.sparql.sparql.SPARQLTypeError(msg)

  Bases: `SPARQLError`

  Parameters:

    msg (`Optional`[`str`])

  __annotations__ = {}
  __firstlineno__ = 52
  __init__(msg)
    Parameters:

      msg (`Optional`[`str`])

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ()

class rdflib.plugins.sparql.sparql.Update(prologue, algebra)

  Bases: `object`

  A parsed and translated update

  Parameters:

    - prologue (`Prologue`)

    - algebra (`List`[`CompValue`])

  __dict__ = mappingproxy({'__module__': 'rdflib.plugins.sparql.sparql', '__firstlineno__': 491, '__doc__': '\nA parsed and translated update\n', '__init__': <function Update.__init__>, '__static_attributes__': ('algebra', 'prologue'), '__dict__': <attribute '__dict__' of 'Update' objects>, '__weakref__': <attribute '__weakref__' of 'Update' objects>, '__annotations__': {'_original_args': 'Tuple[str, Mapping[str, str], Optional[str]]'}})
  __firstlineno__ = 491
  __init__(prologue, algebra)
    Parameters:

      - prologue (`Prologue`)

      - algebra (`List`[`CompValue`])

  __module__ = 'rdflib.plugins.sparql.sparql'
  __static_attributes__ = ('algebra', 'prologue')
  __weakref__

    list of weak references to the object

## rdflib.plugins.sparql.update module

Code for carrying out Update Operations

rdflib.plugins.sparql.update.evalAdd(ctx, u)

  add all triples from src to dst

  http://www.w3.org/TR/sparql11-update/#add

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalClear(ctx, u)

  http://www.w3.org/TR/sparql11-update/#clear

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalCopy(ctx, u)

  remove all triples from dst add all triples from src to dst

  http://www.w3.org/TR/sparql11-update/#copy

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalCreate(ctx, u)

  http://www.w3.org/TR/sparql11-update/#create

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalDeleteData(ctx, u)

  http://www.w3.org/TR/sparql11-update/#deleteData

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalDeleteWhere(ctx, u)

  http://www.w3.org/TR/sparql11-update/#deleteWhere

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalDrop(ctx, u)

  http://www.w3.org/TR/sparql11-update/#drop

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalInsertData(ctx, u)

  http://www.w3.org/TR/sparql11-update/#insertData

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalLoad(ctx, u)

  http://www.w3.org/TR/sparql11-update/#load

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalModify(ctx, u)
  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalMove(ctx, u)

  remove all triples from dst add all triples from src to dst remove all triples from src

  http://www.w3.org/TR/sparql11-update/#move

  Parameters:

    - ctx (`QueryContext`)

    - u (`CompValue`)

  Return type:

    `None`

rdflib.plugins.sparql.update.evalUpdate(graph, update, initBindings=None)

  http://www.w3.org/TR/sparql11-update/#updateLanguage

  ‘A request is a sequence of operations […] Implementations MUST ensure that operations of a single request are executed in a fashion that guarantees the same effects as executing them in lexical order.

  Operations all result either in success or failure.

  If multiple operations are present in a single request, then a result of failure from any operation MUST abort the sequence of operations, causing the subsequent operations to be ignored.’

  This will return None on success and raise Exceptions on error

  Caution

  This method can access indirectly requested network endpoints, for example, query processing will attempt to access network endpoints specified in `SERVICE` directives.

  When processing untrusted or potentially malicious queries, measures should be taken to restrict network and file access.

  For information on available security measures, see the RDFLib Security Considerations documentation.

  Parameters:

    - graph (`Graph`)

    - update (`Update`)

    - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

  Return type:

    `None`

## Module contents

SPARQL implementation for RDFLib

Added in version 4.0.

rdflib.plugins.sparql.CUSTOM_EVALS = {}

  Custom evaluation functions

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

rdflib.plugins.sparql.prepareQuery(queryString, initNs=None, base=None)

  Parse and translate a SPARQL Query

  Parameters:

    - queryString (`str`)

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `Query`

rdflib.plugins.sparql.prepareUpdate(updateString, initNs=None, base=None)

  Parse and translate a SPARQL Update

  Parameters:

    - updateString (`str`)

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `Update`

rdflib.plugins.sparql.processUpdate(graph, updateString, initBindings=None, initNs=None, base=None)

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

  Parameters:

    - graph (`Graph`)

    - updateString (`str`)

    - initBindings (`Optional`[`Mapping`[`str`, `Identifier`]])

    - initNs (`Optional`[`Mapping`[`str`, `Any`]])

    - base (`Optional`[`str`])

  Return type:

    `None`