SPARQLWrapper Documentation
passwd: The password of the credentials for querying the current endpoint. The value can be set an explicit call
setCredentials(). The default value is None. :vartype passwd: string :ivar http_auth: HTTP Authentication
type. The default value is BASIC. Possible values are BASIC or DIGEST. It is used only in case the credentials
are set. :vartype http_auth: string :ivar onlyConneg: Option for allowing (or not) only HTTP Content Negotia-
tion (so dismiss the use of HTTP parameters). The default value is False. :vartype onlyConneg: boolean :ivar
customHttpHeaders: Custom HTTP Headers to be included in the request. It is a dictionary where keys are the
header field and values are the header values. Important: These headers override previous values (including
Content-Type, User-Agent, Accept and Authorization if they are present). :vartype customHttpHeaders:
dict :ivar timeout: The timeout (in seconds) to use for querying the endpoint. :vartype timeout: int :ivar queryS-
tring: The SPARQL query text. :vartype queryString: string :ivar queryType: The type of SPARQL query (aka
SPARQL query form), like CONSTRUCT, SELECT, ASK , DESCRIBE, INSERT, DELETE, CREATE, CLEAR, DROP,
LOAD, COPY, MOVE or ADD (constants in this module). :vartype queryType: string :ivar returnFormat: The return
format. No local check is done, so the parameter is simply sent to the endpoint. Eg, if the value is set to JSON
and a construct query is issued, it is up to the endpoint to react or not, this wrapper does not check. The possible
values are JSON, XML, TURTLE, N3, RDF, RDFXML, CSV, TSV, JSONLD (constants in this module). The default
value is XML. :vartype returnFormat: string :ivar requestMethod: The request method for query or update op-
erations. The possibles values are URL-encoded (URLENCODED) or POST directly (POSTDIRECTLY). :vartype
requestMethod: string :ivar method: The invocation method (HTTP verb). The default value is GET, but it can
be set to POST. :vartype method: string :ivar parameters: The parameters of the request (key/value pairs in a
dictionary). :vartype parameters: dict :ivar _defaultReturnFormat: The default return format. It is used in case
the same class instance is reused for subsequent queries. :vartype _defaultReturnFormat: string
Variables
• prefix_pattern (re.RegexObject, a compiled regular expression. See the re module
of Python) – regular expression used to remove base/prefixes in the process of determining
the query type.
• pattern – regular expression used to determine whether a query (without base/prefixes) is
of type
CONSTRUCT, SELECT, ASK, DESCRIBE, INSERT, DELETE, CREATE, CLEAR , DROP, LOAD, COPY, MOVE or ADD.
:vartype pattern: re.RegexObject, a compiled regular expression. See the re module of Python :cvar com-
ments_pattern: regular expression used to remove comments from a query. :vartype comments_pattern: re.
RegexObject, a compiled regular expression. See the re module of Python
__init__(endpoint: str, updateEndpoint: Optional[str] = None, returnFormat: str = 'xml', defaultGraph:
Optional[str] = None, agent: str = 'sparqlwrapper 2.0.0 (rdflib.github.io/sparqlwrapper)') → None
Class encapsulating a full SPARQL call.
Parameters
• endpoint (string) – SPARQL endpoint’s URI.
• updateEndpoint – SPARQL endpoint’s URI for update operations (if it’s a different one).
The default
value is None. :type updateEndpoint: string :param returnFormat: The return format. No local check
is done, so the parameter is simply sent to the endpoint. Eg, if the value is set to JSON and a construct
query is issued, it is up to the endpoint to react or not, this wrapper does not check. The possible values
are JSON, XML, TURTLE, N3, RDF, RDFXML, CSV, TSV, JSONLD (constants in this module). The default
value is XML. :param defaultGraph: URI for the default graph. The value can be set either via an explicit
call addParameter("default-graph-uri", uri) or as part of the query string. The default value is
None. :type defaultGraph: string :param agent: The User-Agent for the HTTP request header. The default
value is an autogenerated string using the SPARQLWrapper version number. :type agent: string
resetQuery() → None
Reset the query, ie, return format, method, query, default or named graph settings, etc, are reset to their
default values. This includes the default values for parameters, method, timeout or requestMethod.
2.1. SPARQLWrapper.Wrapper module 23