Skip to content

Query

lokf query loads a bundle into an in-memory GraphStore (backed by pyoxigraph) and runs SPARQL over it. Nothing is written; the store lives only for the length of the command.

Terminal window
uv run lokf query examples/acme-knowledge \
'SELECT ?s ?name WHERE { ?s schema:name ?name } ORDER BY ?name'

You never write a PREFIX block. The store prepends the LOKF schema namespaces to every query, so the common prefixes are already bound:

lokf, schema, prov, dcterms, skos, foaf, rdf, rdfs, owl, xsd, and dcat.

Write schema:name, prov:wasDerivedFrom, or lokf:Metric straight away. You can still declare your own PREFIX/BASE lines at the top of a query if you need one that is not preset.

Every named thing in the bundle:

Terminal window
uv run lokf query examples/acme-knowledge \
'SELECT ?s ?name WHERE { ?s schema:name ?name } ORDER BY ?name'
s name
https://acme.example/knowledge/glossary/active-user Active User
https://acme.example/knowledge/services/analytics-api Analytics API
...

--format / -f controls how results come back:

Value Applies to Result
table (default) SELECT aligned columns
json / csv / tsv SELECT / ASK SPARQL results
ttl CONSTRUCT / DESCRIBE Turtle (the default for those forms)

The just query recipe wraps the command:

Terminal window
just query examples/acme-knowledge 'SELECT ?s WHERE { ?s a lokf:Metric }'

lokf query is a wrapper around GraphStore. The store gives you the same queries, plus rdflib_graph(), serialize_results(), and dump():

from lokf.store import GraphStore
store = GraphStore.from_bundle("examples/acme-knowledge")
len(store) # triple count
store.select("SELECT ?s WHERE { ?s a lokf:Metric }")
# -> [{'s': 'https://acme.example/knowledge/metrics/weekly-active-users'}]
store.ask("ASK { ?s a lokf:Metric }") # -> True
store.construct("CONSTRUCT { ?s ?p ?o } WHERE { ?s a lokf:Metric ; ?p ?o }")

The prefixes are preset on the store too — store.prefixes is the dict it prepends. To publish the same store over HTTP, see Serve.