Source code

Download source archive ↓

src/rdflib/plugins/sparql/__init__.py

1"""SPARQL implementation for RDFLib
2
3!!! example "New in version 4.0"
4"""
5
6from importlib.metadata import entry_points
7from typing import TYPE_CHECKING
8
9SPARQL_LOAD_GRAPHS = True
10"""
11If True, using FROM <uri> and FROM NAMED <uri>
12will load/parse more data
13"""
14
15
16SPARQL_DEFAULT_GRAPH_UNION = True
17"""
18If True - the default graph in the RDF Dataset is the union of all
19named graphs (like RDFLib's ConjunctiveGraph)
20"""
21
22
23CUSTOM_EVALS = {}
24"""
25Custom evaluation functions
26
27These must be functions taking (ctx, part) and raise
28NotImplementedError if they cannot handle a certain part
29"""
30
31
32PLUGIN_ENTRY_POINT = "rdf.plugins.sparqleval"
33
34
35from . import operators, parser, parserutils
36from .processor import prepareQuery, prepareUpdate, processUpdate
37
38assert parser
39assert operators
40assert parserutils
41
42
43all_entry_points = entry_points()
44if hasattr(all_entry_points, "select"):
45    for ep in all_entry_points.select(group=PLUGIN_ENTRY_POINT):
46        CUSTOM_EVALS[ep.name] = ep.load()
47else:
48    # Prior to Python 3.10, this returns a dict instead of the selection interface
49    if TYPE_CHECKING:
50        assert isinstance(all_entry_points, dict)
51    for ep in all_entry_points.get(PLUGIN_ENTRY_POINT, []):
52        CUSTOM_EVALS[ep.name] = ep.load()
53
54__all__ = [
55    "prepareQuery",
56    "prepareUpdate",
57    "processUpdate",
58    "operators",
59    "parser",
60    "parserutils",
61    "CUSTOM_EVALS",
62]