Skip to main content

Python client for the little big brain graph + hybrid search HTTP API

Project description

littlebigbrain — Python SDK

The Python client for Little Big Brain — write graph facts, build indexes, and run hybrid search over one 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. Build persisted BM25 + vector + adjacency indexes and wait.
    lbb.indexes.run(wait=True)

    # 3. Hybrid search over the snapshot.
    results = lbb.search.hybrid("how much annual leave do employees get?", top_k=5)
    for hit in results.get("assertions", []):
        print(hit["relation"]["name"], hit["score"])

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); indexes and search are client-level (lbb.indexes, lbb.search) and use the stack's default graph.

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",
)

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.

More

Beyond the quickstart: entities.iter(...) for cursor-safe iteration, context.ask(...) for grounded answers, ontology/schema for the SHACL lifecycle, durable index and training jobs (index_submit/index_job), managed embeddings, traversal, and temporal history. Typed Pydantic responses are available via the matching *_model / *_page helpers; generated models live in lbb.models.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

littlebigbrain-0.6.1.tar.gz (128.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

littlebigbrain-0.6.1-py3-none-any.whl (112.1 kB view details)

Uploaded Python 3

File details

Details for the file littlebigbrain-0.6.1.tar.gz.

File metadata

  • Download URL: littlebigbrain-0.6.1.tar.gz
  • Upload date:
  • Size: 128.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for littlebigbrain-0.6.1.tar.gz
Algorithm Hash digest
SHA256 c860c987d8849bf90f3355e62e5c2e0bccb7d77e507decc02caa7532054770fe
MD5 b892009b38b36506557654bde2a68624
BLAKE2b-256 f7779098283f9e559e1f73b62294fba9a4d68d4b7b31e4873d1f9ce11a4cf301

See more details on using hashes here.

Provenance

The following attestation bundles were made for littlebigbrain-0.6.1.tar.gz:

Publisher: release.yml on littlebigbrains/lbb-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file littlebigbrain-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: littlebigbrain-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 112.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for littlebigbrain-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71b4fe62a515c3a8b56f869731d11e8eed3b87fe63eff13ae8ebb4ecfe2132c9
MD5 316a56a914413be051c9418428225048
BLAKE2b-256 af08824d5998f7bfd836024147805a168269ea0630b13e5629f28f01af20cf8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for littlebigbrain-0.6.1-py3-none-any.whl:

Publisher: release.yml on littlebigbrains/lbb-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page