Skip to main content

littlebigbrain — Python SDK

The Python client for Little Big Brain — write graph facts and query one immutable published snapshot. Built on httpx + pydantic; ships sync and async clients.

pip install littlebigbrain   # imports as `lbb`

Quickstart

from lbb import LbbClient

with LbbClient(
    "https://0abc1def--production.db.eu.littlebigbrain.com",
    api_key="lbb_sk_live_...",
    graph="main",
) as lbb:
    graph = lbb.graph("main")

    # 1. Write a fact.
    graph.facts.create({
        "triplets": [{
            "source": {"type": "CONCEPT", "name": "handbook", "key": "doc:42"},
            "relation": "RELATED_TO",
            "target": {"type": "CONCEPT", "name": "vacation policy", "key": "passage:42:1"},
            "evidence": "Employees receive 25 days of annual leave.",
        }],
    }, idempotency_key="doc:42:v1")

    # 2. Publication is automatic. Inspect one coherent watermark when needed.
    published = lbb.read_snapshot_model()
    print(published.snapshot.served_at_seq, published.query_lag_commits)

    # 3. Query the snapshot with SPARQL.
    rows = lbb.sparql_select(
        "SELECT ?s ?o WHERE { ?s <policy:annual_leave> ?o } LIMIT 5"
    )
    for row in rows:
        print(row["s"], row["o"])

For hosted use, pass the exact endpoint_url shown on the stack's Connect page. Omitting base_url retains the loopback default for local/self-hosted development only; graph and branch remain ordinary client scope parameters.

Facts are graph-scoped (lbb.graph("main").facts); search and published-snapshot inspection use the client's active graph/branch scope.

Examples

Search with filters. Use the request body to filter before ranking — here, only facts an ACL principal may see:

results = lbb.graph_search({
    "query": "incident response runbook",
    "targets": ["entities"],
    "search": {
        "filters": {
            "op": "overlaps",
            "field": "acl",
            "values": ["user:rino@example.com", "group:engineering"],
        },
    },
    "top_k": 20,
})

Bulk import. Load many records as NDJSON in one call:

lbb.graph("main").facts.import_ndjson(
    [
        {"source": {"type": "DOC", "name": "handbook", "key": "doc:42"},
         "relation": "HAS_PASSAGE",
         "target": {"type": "PASSAGE", "name": "leave-policy", "key": "p:42:1"}},
        # …one record per line
    ],
    idempotency_key="handbook-batch-1",
)

For large or long-running loads, submit a streamed durable job:

accepted = lbb.submit_import_ndjson(
    records(),
    idempotency_key="hubspot:portal-42:run-2026-07-29",
)
completed = lbb.wait_for_import_job(accepted.job_id)
print(completed.state, completed.committed_commit_seq)
if completed.committed_commit_seq is not None:
    lbb.wait_for_index_lineage(completed.committed_commit_seq.root)

The async client accepts an async iterable as well. Success means all grouped commits are durable and final publication was enqueued; it does not mean published indexes have already reached committed_commit_seq. Wait once after the final commit, not after each source row or chunk. The lineage waiter polls normal index_caught_up=false metadata until its own deadline, including on an RDF-only deployment. Empty iterables are rejected locally before an import POST is sent.

Time-travel read. Pin a SPARQL query to a past instant — results reflect the graph as it was then:

results = lbb.sparql(
    "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10",
    as_of_valid_time="2026-01-01T00:00:00Z",
)
print(results.vars)
for row in results:           # iterates flat {var: value} dicts
    print(row)

The async client mirrors every method — async with AsyncLbbClient(...) as lbb: and await each call.

Errors & retries

Methods return parsed dictionaries and raise LbbError (with status_code, code, param, request_id, and doc_url) on any non-2xx response. Safe reads and idempotency-keyed writes retry 429/5xx and transport failures with full-jitter backoff, bounded by a retry budget (retry_budget_ms, default 60s) rather than a fixed count, and honor Retry-After — a terminal error the server marks non-retryable surfaces immediately. Use raw_request(...) for response headers, request id, and retry/timing metadata. wait_for_index_lineage(...) is a separate deadline-bounded poller, so the generic request retry-count cap cannot end publication waiting early.

More

Beyond the quickstart: entities.sample(type=..., limit=...) for a bounded published-generation sample and entities.filter_by_attributes(...) for relation-bound structured SPARQL; and ontology/schema for ontology inspection and atomic schema publication. SPARQL is the one query language on the API. Typed Pydantic responses are exposed by matching *_model helpers; generated models live in lbb.models. Retired request-time JSON SHACL DTOs are intentionally absent: publish RDF shapes with schema.publish, then read ontology.conformance.

Full reference and guides: docs.littlebigbrain.com/sdks/python.

Develop

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
ruff check lbb tests
mypy lbb
pytest tests

lbb/models.py is generated from the API contract — change the Rust API types and regenerate rather than editing it by hand.

Release files for littlebigbrain 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for littlebigbrain 0.12.0
File Size Uploaded
littlebigbrain-0.12.0.tar.gz 112.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for littlebigbrain 0.12.0
File Interpreter ABI Platform
littlebigbrain-0.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 209.7 kB

Release files / littlebigbrain-0.12.0.tar.gz

Download URL littlebigbrain-0.12.0.tar.gz
Size 112.8 kB
Tags Source
SHA-256 checksum
How to use checksums
152bda69fa65c3641a73111e821ba3edcdea83559faf9a22281204b4565e7d3a
BLAKE2b-256 checksum
How to use checksums
ccb4e84fc82204336060c588759f6542a8f4209736931a6632bbcf92e1decd4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Release files / littlebigbrain-0.12.0-py3-none-any.whl

Download URL littlebigbrain-0.12.0-py3-none-any.whl
Size 96.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abe18dfa09a47c8e17c7ad66e71d681649ca2ea24a1f5840d5d862eb9da4e638
BLAKE2b-256 checksum
How to use checksums
494c0ac98df6cad088990dad7d5fee5ba94bdbc5f2442b9afce8d6adc741c8fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.

Transparency log

Release history Release notifications | RSS feed

0.14.0

2 release files

0.13.1

2 release files

0.13.0

2 release files

This release

0.12.0 This release

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page