Example code: Querying the database

The most general query method is triples(), which takes a (subject, property, object) 3-tuple, returning an iterator over the matching triples. Each element of the tuple can contain a URIRef or Literal instance, or None to match anything.

For example, to list all things which have a dc:title property:

>>> DC_TITLE = URIRef('http://purl.org/dc/elements/1.1/title')
>>> for s,p,o in store.triples((None, DC_TITLE, None)):
... print s,p,o
...
urn:isbn:0609602330 http://purl.org/dc/elements/1.1/title "Isaac's Storm".
urn:isbn:1930110111 http://purl.org/dc/elements/1.1/title "XSLT Quickly".
>>>