Skip to content

Toolkit

The lokf Python package is the toolkit around the format: everything you need to load a bundle, inspect the vocabulary, project markdown to RDF, query it with SPARQL, serve it locally, propose typed relations from prose links, and export the result as a graph or as schema.org JSON-LD. It also federates bundles through a registry. It comes with a CLI and an MCP server so agents can drive all of it. The CLI’s commands are lokf new, validate, convert, query, serve, propose, vocab, adapt, tables, export, registry, skills and mcp. The format itself stays where it belongs — in lokf.yaml and the specification; the toolkit never hardcodes a type or predicate it can read from the schema.

Module What it gives you
lokf.model load_bundle() → Bundle / Concept objects, JSON-LD and rdflib.Graph projection
lokf.rdf serialize() / graph_of() — project markdown to RDF (lokf convert)
lokf.store GraphStore — an in-memory pyoxigraph store for SPARQL (lokf query)
lokf.server serve() — a local SPARQL endpoint + graph explorer (lokf serve)
lokf.schema vocabulary() → the typed-relation slots and RelationType vocabulary, straight from lokf.yaml
lokf.adapt adapt() — a published LinkML schema as a domain vocabulary (lokf adapt)
lokf.parse frontmatter parsing helpers (parse_concept, isoify)
lokf.propose heuristic relation proposer + the lokf propose CLI
lokf.export Cytoscape.js graph elements and schema.org Dataset JSON-LD; lokf export writes the four files a registry harvests
lokf.registry Registry: a manifest of bundles, each in its own named graph (lokf registry)
lokf.mcp_server the lokf mcp / lokf-mcp MCP server that exposes the toolkit to agents
lokf.build the lokf-build console script that regenerates every artifact

Installing lokf gives you the CLI (lokf), the MCP server (lokf-mcp), and the bundled agent skills:

Terminal window
uv pip install lokf

The core install is lean — just typer, rdflib, pyoxigraph, and mcp. It reads the committed schema and context directly, so it can convert, query, serve, and propose without a heavy dependency tree. The one thing it leaves out is LinkML, needed to regenerate the artifacts from lokf.yaml and to run lokf validate; that lives behind the build extra:

Terminal window
uv pip install 'lokf[build]' # adds linkml for lokf-build and lokf validate

lokf --version (or lokf -V) prints the installed version — a quick check that the CLI is on your PATH.

Working inside a clone of this repository? uv sync already installs the package (with the build extra) in editable mode — see Getting started.

Everything below runs against the committed reference bundle, from the repository root:

import lokf
# Load a bundle: a directory of markdown files, nothing else.
bundle = lokf.load_bundle("examples/acme-knowledge")
len(bundle.concepts) # -> 6
bundle.base_iri # -> 'https://acme.example/knowledge/'
# Concepts are addressable by Concept ID, path, or IRI.
wau = bundle.get("metrics/weekly-active-users")
wau.type, wau.title # -> ('Metric', 'Weekly Active Users')
wau.data["formula"] # frontmatter is a plain dict (body included)
# The same bundle, as RDF — this is the committed 86-triple projection.
g = bundle.graph()
len(g) # -> 86
print(g.serialize(format="turtle"))

And the vocabulary side — the typed-relation fields, read from the LinkML schema rather than hardcoded:

vocab = lokf.vocabulary()
sorted(vocab.relation_slots)
# -> ['about', 'definedBy', 'dependsOn', 'derivedFrom', 'hasPart', 'isPartOf',
# 'measures', 'references', 'relatedTo', 'sameAs', 'source']
vocab.relation_slots["derivedFrom"].curie # -> 'prov:wasDerivedFrom'
vocab.relation_slots["measures"].domains # -> frozenset({'Metric'})
vocab.expand("prov:wasDerivedFrom") # -> 'http://www.w3.org/ns/prov#wasDerivedFrom'

The same vocabulary is available from the CLI. lokf vocab prints the typed-relation table; lokf vocab --all widens it to the whole schema reference — every class, frontmatter slot and value enum with its own description — and --json emits either as JSON:

Terminal window
lokf vocab # the typed-relation vocabulary
lokf vocab --all --json # the full reference, machine-readable

Agents get the same thing from the MCP server’s get_vocabulary tool, which takes an all flag with the same meaning.

  • Build your own knowledge base — from an empty directory to a validated, queryable bundle: authoring, validation, proposals, RDF, and a graph view. See the Tutorial.
  • Relation proposer — how lokf propose turns prose links into typed-relation suggestions, and where its heuristics stop. See the Proposer.
  • Knowledge graph — the reference bundle rendered as an interactive graph, built with lokf.export and the generated site’s shared explorer. See the Knowledge graph.
  • Publish a site — lokf new creates concept pages, full-text search, and scoped graph exploration on a static host. See Scaffold a knowledge base.
  • Python reference — generated API docs for every module in the package. See the API reference.