Integration API
The Python and TypeScript clients
Two single-file clients ship with the server, with no dependencies:
| File | Needs |
|---|---|
clients/python/graphlife.py |
Python 3, standard library only (tested on 3.12) |
clients/typescript/graphlife.ts |
fetch (Node 18 or later, Deno, Bun or a browser); runs under Node's type stripping as it is (tested on Node 22) |
Both find out on their first call whether the address is a GraphLife server
or the separate single-graph gateway, by asking /health without the key.
Pass transport="server" (TypeScript: { transport: "server" }) to skip
that. If /health gives no clear answer the call fails with
transport_unknown and the question is asked again next time.
Python#
from graphlife import GraphLife, GraphLifeError
gl = GraphLife("https://graphlife.example.com", "glk_...") # key: list_nodes, changes
for node in gl.iter_nodes(kind="event"): # every page, in id order
store(node)
token = gl.last_sync_token # where the copy stands
try:
for event in gl.iter_changes(token, poll=True): # waits for the next one
apply(event, gl.get_nodes([event["id"]]))
save(gl.last_sync_token)
except GraphLifeError as e:
if e.code != "resync_required":
raise # reset: list again
TypeScript#
import { GraphLife, GraphLifeError } from "./graphlife.ts";
const gl = new GraphLife("https://graphlife.example.com", "glk_...");
for await (const node of gl.iterNodes({ kind: "event" })) store(node);
const token = gl.lastSyncToken;
try {
for await (const event of gl.iterChanges(token, { poll: true })) {
apply(event, await gl.getNodes([event.id]));
save(gl.lastSyncToken);
}
} catch (e) {
if (!(e instanceof GraphLifeError) || e.code !== "resync_required") throw e;
}
What they do for you#
| Python | TypeScript | Does |
|---|---|---|
call(tool, **args) |
call(tool, args) |
any tool by name |
tools() |
tools() |
what the key may call |
stats, search, node, neighbors, subgraph, paths, context, ask |
the same, camelCase | reads |
get_nodes(ids) |
getNodes(ids) |
any number of ids, sent 100 at a time |
list_nodes / iter_nodes, list_edges / iter_edges |
listNodes / iterNodes, listEdges / iterEdges |
one page, or every page |
changes(since, limit=, wait=) / iter_changes(since, poll=) |
changes(since, {limit, wait}) / iterChanges(since, {poll}) |
the change feed |
add_to_graph, add_capture, add_edge, update_node, delete_node, delete_edge, restore_node, create_group, set_groups |
the same, camelCase | writes |
rotate_key(overlap_seconds=3600) |
rotateKey(overlapSeconds) |
rotates, switches the client to the new secret and returns the answer: store token |
GraphLife.verify_webhook(secret, timestamp, body, signature) |
await GraphLife.verifyWebhook(...) |
checks a delivery's signature |
- The iterators page on
hasMoreandnextCursoronly, so an empty page with more to come is read past.last_sync_token(lastSyncToken) is the first page's token after a listing, and follows along duringiter_changes. iter_changesraisesGraphLifeError(409, "resync_required")on a reset; the feed'snextis in the error'sdetail.GraphLifeErrorcarriesstatus,code,message,request_id,retry_afteranddetail(the whole error object).- A
429is waited out (Retry-After, at most 60 s) and sent again, up tomax_retries(3) times, writes included. A5xxor a dropped connection is retried for reads only. - The default timeout is 30 seconds (
GraphLife(base, key, 5.0),new GraphLife(base, key, 5000)). A long poll is given the wait plus ten seconds when the client's timeout is shorter. - When the credential reaches more than one graph, pass
graph=to the constructor ({ graph }in TypeScript). viewer=andme()belong to the gateway and raiseunsupported_on_server.context()returns the text withtokens0, meaning unknown.
clients/python/selftest.py and clients/typescript/selftest.ts exercise
every one of these against a server you point them at. They write to the
graph, so use a test graph:
python clients/python/selftest.py https://graphlife.example.com glk_...
node --experimental-strip-types clients/typescript/selftest.ts https://graphlife.example.com glk_...