query
Classes:
-
EncodeOnlyUnicode–This is a crappy work-around for http://bugs.python.org/issue11649
-
Processor–Query plugin interface.
-
Result–A common class for representing query result.
-
ResultException– -
ResultParser– -
ResultRow–A single result row allows accessing bindings as attributes or with []
-
ResultSerializer– -
UpdateProcessor–Update plugin interface.
__all__
module-attribute
__all__ = ['Processor', 'UpdateProcessor', 'Result', 'ResultRow', 'ResultParser', 'ResultSerializer', 'ResultException', 'EncodeOnlyUnicode']
EncodeOnlyUnicode
This is a crappy work-around for http://bugs.python.org/issue11649
Methods:
-
__getattr__– -
write–
__getattr__
Processor
Processor(graph: Graph)
Query plugin interface.
This module is useful for those wanting to write a query processor that can plugin to rdf. If you are wanting to execute a query you likely want to do so through the Graph class query method.
Methods:
-
query–
query
query(strOrQuery: Union[str, Query], initBindings: Mapping[str, Identifier] = {}, initNs: Mapping[str, Any] = {}, DEBUG: bool = False) -> Mapping[str, Any]
Source code in rdflib/query.py
Result
A common class for representing query result.
There is a bit of magic here that makes this appear like different Python objects, depending on the type of result.
If the type is “SELECT”, iterating will yield lists of ResultRow objects
If the type is “ASK”, iterating will yield a single bool (or bool(result) will return the same bool)
If the type is “CONSTRUCT” or “DESCRIBE” iterating will yield the triples.
len(result) also works.
Methods:
-
__bool__– -
__eq__– -
__getattr__– -
__iter__– -
__len__– -
parse–Parse a query result from a source.
-
serialize–Serialize the query result.
Attributes:
-
askAnswer(Optional[bool]) – -
bindings(MutableSequence[Mapping[Variable, Identifier]]) –a list of variable bindings as dicts
-
graph(Optional[Graph]) – -
type– -
vars(Optional[List[Variable]]) –a list of variables contained in the result
Source code in rdflib/query.py
bindings
property
writable
bindings: MutableSequence[Mapping[Variable, Identifier]]
a list of variable bindings as dicts
vars
instance-attribute
vars: Optional[List[Variable]] = None
a list of variables contained in the result
__bool__
__eq__
Source code in rdflib/query.py
__getattr__
Source code in rdflib/query.py
__iter__
__iter__() -> Iterator[Union[_TripleType, bool, ResultRow]]
Source code in rdflib/query.py
__len__
Source code in rdflib/query.py
parse
staticmethod
parse(source: Optional[IO] = None, format: Optional[str] = None, content_type: Optional[str] = None, **kwargs: Any) -> Result
Parse a query result from a source.
Source code in rdflib/query.py
serialize
serialize(destination: Optional[Union[str, IO]] = None, encoding: str = 'utf-8', format: str = 'xml', **args: Any) -> Optional[bytes]
Serialize the query result.
Parameters:
-
(destinationOptional[Union[str, IO]], default:None) –Path of file output or BufferedIOBase object to write the output to. If
Nonethis function will return the output asbytes -
(encodingstr, default:'utf-8') –Encoding of output.
-
(formatstr, default:'xml') –
Returns:
-
Optional[bytes]–Serialized result, when destination is not given.
Source code in rdflib/query.py
ResultException
Bases: Exception
ResultParser
Methods:
-
parse–return a Result object
ResultRow
Bases: Tuple[Identifier, ...]
A single result row allows accessing bindings as attributes or with []
>>> from rdflib import URIRef, Variable
>>> rr=ResultRow({ Variable('a'): URIRef('urn:cake') }, [Variable('a')])
>>> rr[0]
rdflib.term.URIRef('urn:cake')
>>> rr[1]
Traceback (most recent call last):
...
IndexError: tuple index out of range
>>> rr.a
rdflib.term.URIRef('urn:cake')
>>> rr.b
Traceback (most recent call last):
...
AttributeError: b
>>> rr['a']
rdflib.term.URIRef('urn:cake')
>>> rr['b']
Traceback (most recent call last):
...
KeyError: 'b'
>>> rr[Variable('a')]
rdflib.term.URIRef('urn:cake')
New in version 4.0
Methods:
-
__getattr__– -
__getitem__– -
__new__– -
asdict– -
get–
Attributes:
-
labels(Mapping[str, int]) –
__getattr__
__getattr__(name: str) -> Identifier
__getitem__
__getitem__(name: Union[str, int, Any]) -> Identifier
Source code in rdflib/query.py
__new__
__new__(values: Mapping[Variable, Identifier], labels: List[Variable])
Source code in rdflib/query.py
asdict
asdict() -> Dict[str, Identifier]
get
get(name: str, default: Identifier) -> Identifier
get(name: str, default: Optional[Identifier] = ...) -> Optional[Identifier]
get(name: str, default: Optional[Identifier] = None) -> Optional[Identifier]
ResultSerializer
ResultSerializer(result: Result)
UpdateProcessor
UpdateProcessor(graph: Graph)
Update plugin interface.
This module is useful for those wanting to write an update processor that can plugin to rdflib. If you are wanting to execute an update statement you likely want to do so through the Graph class update method.
New in version 4.0
Methods:
-
update–
update
update(strOrQuery: Union[str, Update], initBindings: Mapping[str, Identifier] = {}, initNs: Mapping[str, Any] = {}) -> None