Skip to main content

littlebigbrain Python SDK

Python client for little big brain, a search platform for AI applications such as chatbots, search tools, and agents. Load facts, query their relationships, and keep the data version behind an answer so you can check it later.

The package supports Python 3.10+ and provides synchronous and asynchronous clients built on httpx. Generated Pydantic models are available in lbb.models.

Documentation · Quickstart · Issues

Install

pip install littlebigbrain

The package is installed as littlebigbrain and imported as lbb.

Load facts and run a query

Create a stack in the console and open Connect. Copy its complete endpoint and a stack API key:

export LBB_URL="https://<your-complete-stack-host>"
export LBB_API_KEY="<your-stack-api-key>"

This example creates a graph named quickstart on its first write. It stores three facts: a service writes to a database, and each has a label. The data uses Resource Description Framework (RDF), where each line names a subject, a relationship, and a value or another record. SPARQL is the query language for those facts.

Save as quickstart.py, then run python3 quickstart.py:

import os

from lbb import LbbClient

facts = """
<https://example.org/auth-service> <https://example.org/writesTo> <https://example.org/user-db> .
<https://example.org/auth-service> <http://www.w3.org/2000/01/rdf-schema#label> "Auth Service" .
<https://example.org/user-db> <http://www.w3.org/2000/01/rdf-schema#label> "User Database" .
"""

query = """
    SELECT ?service ?database WHERE {
        ?s <https://example.org/writesTo> ?db .
        ?s <http://www.w3.org/2000/01/rdf-schema#label> ?service .
        ?db <http://www.w3.org/2000/01/rdf-schema#label> ?database .
    } ORDER BY ?service ?database LIMIT 10
"""

with LbbClient(
    os.environ["LBB_URL"],
    api_key=os.environ["LBB_API_KEY"],
    graph="quickstart",
) as lbb:
    imported = lbb.graph("quickstart").facts.import_rdf(
        facts, format="ntriples", idempotency_key="sdk-quickstart-v1"
    )

    results = lbb.sparql(
        query,
        consistency="strong",
        min_indexed_seq=imported["committed_commit_seq"],
    )
    for row in results:
        print(f"{row['service']} -> {row['database']}")

On a fresh graph, this prints:

Auth Service -> User Database

The query follows the stored relationship between the service and database. consistency="strong" makes the new facts available to this read without waiting for a background index job. Reads default to eventual consistency, so omit this option only when an earlier version is acceptable.

The idempotency key makes repeating the same import safe. Use a new key if you change the data.

Async client

AsyncLbbClient provides the same methods with await. After running the quickstart, this script reads its data:

import asyncio
import os

from lbb import AsyncLbbClient


async def main():
    async with AsyncLbbClient(
        os.environ["LBB_URL"],
        api_key=os.environ["LBB_API_KEY"],
        graph="quickstart",
    ) as lbb:
        result = await lbb.sparql(
            "ASK { ?s <https://example.org/writesTo> ?db }",
            consistency="strong",
        )
        print(result.boolean)  # True


asyncio.run(main())

Ask a question in plain words

query.ask turns a question into a SPARQL query, runs it, and returns the rows. A router model selects the kind of query. A rewriter model writes the query from a description of the graph. The server checks the query before it runs it.

answer = lbb.query.ask(
    "Which services write to the user database?",
    context="Services and databases of the platform team.",
)

print(answer.route["kind"], answer.query and answer.query["sparql"])
for row in answer.rows:
    print(row)

The graph can keep notes and worked examples that the rewriter reads for every question. Store them with query.set_rewrite_profile(notes=..., examples=..., expected_version=...) and read them with query.rewrite_profile(). A call's context still adds notes for that call.

answer.error holds the error when the query did not run. answer.trace_id names the eval trace of the run, so you can label its rows. query.rewrite returns the query without a run, and mode="route" returns only the kind of query. Each call uses model tokens, so the client does not retry a failed call.

The server finds the names in the question ("Quelmann", "TU Dresden") in the graph, and the query uses the IRIs it found. answer.linked lists them, so you can show "Did you mean …?". When the user has a record open, pass its IRI in anchor (anchor=[iri], at most 10).

A question about a date ("Which findings were open on 18 June?") reads the last commit written by the end of that day. answer.history names the commit and how the server found it. When your commits stand for other dates (a demo's milestones, an import of old records), pass timeline: timeline=[{"date": "2026-06-18", "as_of_commit_seq": 5, "label": "Addendum"}]. A question that asks what changed runs at both points, and answer.history["added"] and answer.history["removed"] hold the rows that differ.

Show progress

query.rewrite_stream sends the same request and yields an event for each step. The last event, done, holds the same response as query.rewrite.

from lbb import QueryAskResult

for event in lbb.query.rewrite_stream(
    "Which services write to the user database?", run=True
):
    if event.event == "route":
        print("route", event.data["kind"])
    elif event.event == "rows":
        print(event.data["count"], "rows")
    elif event.event == "done":
        answer = QueryAskResult.from_response(event.data)

The steps are grounding, route, query, run, rows and repair. An error event raises the same LbbError as query.rewrite. Leave the loop, or call close(), to close the response and stop the server's work. On AsyncLbbClient, use async for and aclose(). The client skips event names it does not know.

Next steps

The RDF and JSON guides use different write workflows. Choose one when creating a graph; a graph first written through RDF import does not accept facts.create or JSON record imports.

Integrations for your customers

client.integrations connects each of your customers' HubSpot, Linear, SharePoint or Google Drive to a graph of their own. Its routes are on the integrations API, https://api.littlebigbrain.com by default (integrations_url). They take the same stack API key. An operator turns on developer access per stack; ask us first. AsyncLbbClient has the same methods, with await.

graph = "c-5f1c9a0e3b7d2c4a8e6f1b0d"  # one opaque graph per customer

lbb.integrations.create(
    graph=graph, id="hubspot", kind="hubspot", credentials={"HUBSPOT_TOKEN": token}
)
connections = lbb.integrations.list(graph=graph)["connections"]
open_ = lbb.integrations.suggestions("hubspot", graph=graph, status="open")
lbb.integrations.accept(open_.suggestions[0].suggestion_id, graph=graph, sync=True)
lbb.integrations.erase(graph, confirm=graph)

Google Drive connects through your own Google app. lbb.google_drive builds the consent URL and turns the callback's code into the connection's credentials (exchange_code_async for async code):

from lbb import google_drive

url = google_drive.authorize_url(client_id=client_id, redirect_uri=redirect_uri, state=state)
# On the callback, after `state` matches:
grant = google_drive.exchange_code(
    client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, code=code
)
lbb.integrations.create(
    graph=graph, id="google-drive", kind="google_drive", credentials=grant.credentials
)

See Integrations for your customers.

Errors and retries

Failed HTTP requests raise LbbError, with a status, error code, message, and request ID. Use raw_request() when you also need response headers or timing.

Safe reads and writes with an idempotency key retry rate limits, retryable server errors, and network failures. Retries respect Retry-After and use a 60-second budget by default. See the client reference for timeout and retry options.

Development

From a clone of this repository:

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

lbb/models.py is generated from the API contract. See CONTRIBUTING.md for changes to generated models.

License

Apache-2.0.

Metadata

Release files for littlebigbrain 0.20.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.20.0
File Size Uploaded Provenance Actions
littlebigbrain-0.20.0.tar.gz 211.3 kB With provenance Details for littlebigbrain-0.20.0.tar.gz

Built distribution (wheel)

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

Total release size: 381.5 kB

Release files / littlebigbrain-0.20.0.tar.gz

Download URL littlebigbrain-0.20.0.tar.gz
Size 211.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4b75a0ac0efeeb7bf2514f2c9b596c324d891bbe3d58290497b0b56da174ac71
BLAKE2b-256 checksum
How to use checksums
e3fd11894a3f711c2ec19a3351a05cbc346a63fbcf45c9b6225a6277e84334ca
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 Oct 5, 2026.

Transparency log

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

Download URL littlebigbrain-0.20.0-py3-none-any.whl
Size 170.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
714db0f9127455252b60bdd7a071248cf53ceda1d24b8f788cc40f1a228e4814
BLAKE2b-256 checksum
How to use checksums
db25de14643961562afe8c166ed96412e33c205a57eca889e09aa34c15e1287a
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 Oct 5, 2026.

Transparency log

Security for littlebigbrain 0.20.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for littlebigbrain-0.20.0.tar.gz

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 Oct 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 release files Full provenance

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