Skip to content

Python — lbb

lbb is the Python client. The HTTP client (LbbClient / AsyncLbbClient) is the integration path for applications; it talks to lbb-server with a stack API key or single-mode token as a bearer credential — the same surface the TypeScript SDK, CLI, and MCP server use. Built on httpx + pydantic.

Terminal window
pip install lbb-sdk # provides the `lbb` package
from lbb import LbbClient, LbbError
with LbbClient("https://db.eu.littlebigbrain.com", api_key="lbb_sk_live_...") as lbb:
# Write facts.
lbb.graph("main").facts.create({
"triplets": [{
"source": {"type": "SERVICE", "name": "auth-service"},
"relation": "WRITES_TO",
"target": {"type": "DATABASE", "name": "user-db"},
"confidence": 0.93,
"evidence": "auth-service writes identity records to user-db",
}],
}, idempotency_key="import-2026-06-13")
# Build indexes.
lbb.indexes.run(wait=True)
# Hybrid search.
results = lbb.search.hybrid(
"which systems store customer identity data",
top_k=5, source="persisted", consistency="strong",
targets=["entities", "assertions"],
)
for assertion in results.get("assertions", []):
print(assertion["relation"]["name"], assertion["score"])

Regular methods return parsed JSON dictionaries and raise LbbError with status_code, type, code, param, request_id, and doc_url on a non-2xx response. Use raw_request(...) when you need response metadata.

The async client mirrors every method:

from lbb import AsyncLbbClient
async with AsyncLbbClient("https://db.eu.littlebigbrain.com", api_key="lbb_sk_live_...") as lbb:
state = await lbb.current_state({"entity": {"entity_type": "SERVICE", "name": "auth-service"}})
page = await lbb.entities.list_page(fields=["title", "status"])

graph("main").facts.create; search.hybrid; indexes.run; entities.list; entities.filter_by_attributes; schema.view / schema.preview / schema.publish / schema.audit; plus the lower-level graph_search, multi_search, full_text_search, embedding_search, traverse, semantic_traverse, current_state, history, why, shacl, sparql (text → parsed results), sparql_select (structured SELECT/ASK/aggregate), analytics, ontology_view (counts=True for per-relation edge_count), ontology_search, ontology_resolve, search_feedback / search_feedback_export, graph_edges, index_build, index_run, index_delta, index_gc, compact, status, metadata, and summary.

The dict-returning methods are stable for scripts and notebooks. For app code that wants generated Pydantic models and IDE autocompletion, use the matching *_model or *_page helper. For how the models are generated and a cross-reference of the common type names, see Types & generated models.

from lbb.models import GraphSummaryResponse, SchemaBundleView
summary: GraphSummaryResponse = lbb.summary_model()
schema: SchemaBundleView = lbb.schema.view_model()
entities = lbb.entities.list_page(fields="*")
for row in entities.data:
print(row.name, row.attributes or {})
raw = lbb.raw_request("GET", "/v1/graph/summary")
typed = raw.model(GraphSummaryResponse)

Typed helpers cover the high-use surfaces: commit_model, commit_dry_run_model, graph("main").facts.create_model, graph("main").retract_model, summary_model, metadata_model, list_graphs_model, ontology_view_model, ontology_conformance_model, sparql_select_model, schema.view_model, schema.preview_model, schema.publish_model, schema.audit_model, entities.list_page, entities.filter_by_attributes_model, and graph_edges_page. Async clients expose the same helpers as awaitables.

client.sparql(query) runs SPARQL 1.1 text (SELECT or ASK) through the conformant engine and returns a parsed SparqlResults — no manual json.loads:

results = lbb.sparql("""
SELECT ?service ?db WHERE {
?service <https://littlebigbrain.com/r/writes_to> ?db
} LIMIT 10
""")
print(results.vars) # ['service', 'db']
for row in results: # iterates flat {var: value} dicts
print(row["service"], "->", row["db"])
answer = lbb.sparql("ASK { ?s ?p ?o }").boolean # True / False

SparqlResults exposes .vars, .boolean (ASK), .bindings (raw typed terms), .rows() (flattened dicts, also what iteration yields), and .row_page. Engine extensions are keyword args: reason=True folds rule-derived edges, entailment="none" disables the default rdfs:subClassOf closure, and as_of_valid_time / as_of_commit_seq pin a snapshot. For the structured BGP form, client.sparql_select(body) returns the typed vars/solutions/groups response.

lbb.entities.filter_by_attributes(
patterns=[{"subject": {"var": "service"}, "predicate": "WRITES_TO", "object": {"var": "db"}}],
where=[{"field": "slo", "op": "ge", "value": 0.99}, {"var": "db", "field": "tier", "value": "prod"}],
select=["service"],
)

Bodies may be plain dicts or instances of the generated Pydantic models in lbb.models (e.g. lbb.models.SemanticGraphSearchRequest).