Brain Docs

Reference

Python SDKInstallationHTTP clientWire clientSync vs async
txn_begintxn_committxn_abort
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
Python SDKTransactionstxn_begin

txn_begin

Open a transaction with an id you generate, and a timeout the server may lower.

PURPOSE

Open a transaction. The id is client-assigned, which is what makes a retry of the begin itself idempotent. Writes join the transaction by carrying that id.

Handshake credentialstable
txn_begin(request: TxnBeginRequest) -> TxnBeginResponse

Parameters

ParameterTypeRequired
txn_idUUID bytesrequired

The id you generate, with the SDK's id helper.

timeout_secondsintegerrequired

How long the server holds it open. Exceeding it is TransactionTimeout and the transaction is gone — the writes inside it did not land.

act_asActAs | nulloptional

Run the transaction as another space.

Returns

FieldTypePresence
txn_idUUID bytesalways

Echoed back.

timeout_secondsintegeralways

The timeout the server actually granted — which may be lower than you asked for. Schedule your own deadline from this value, not from the one you sent.

started_at_unix_nanos64-bit integeralways

When the server opened it.

Example

from brain_db_sdk import new_id, EncodeBuilder
from dataclasses import replace

txn_id = new_id()
client.txn_begin(TxnBeginRequest(txn_id=txn_id, timeout_seconds=30))

req = EncodeBuilder("Priya moved to Lisbon.").build()
client.encode(replace(req, txn_id=txn_id))

client.txn_commit(TxnCommitRequest(txn_id=txn_id))

HTTP has no transactions

The HTTP edge exposes no transaction routes. Each HTTP verb is its own unit. If several writes must land together, you need the wire client — see Wire client.

Joining writes to it

Every mutating wire request type carries a txnId field. Setting it is what puts the write inside the transaction.

The builders do not set txnId

The encode, recall and forget builders all leave txnId null and offer no method to change it. Build the request, then set the field before sending. A write you believe is in a transaction but whose txnId is null lands immediately and is not rolled back by an abort.

See also
txn_committxn_abort

Was this page helpful?

cancel_stream

Stop an in-flight multiplexed stream server-side — abandoning the call does not.

txn_commit

Apply a transaction's writes atomically, and check that every write actually joined it.

On this page

ParametersReturnsExampleJoining writes to it
Suggest an editOpen in Playground