Skip to main content
RushDB 2.x (legacy, Neo4j-based). Security fixes only until 2027-10-28.
New projects: use RushDB 3, a standalone Rust database for AI.

Transaction

A Transaction groups multiple database operations so they succeed or fail together. Obtain one via db.tx.begin(), then pass it to any write method. Call commit() to make changes permanent or rollback() to discard them.

Class Definition​

Python
class Transaction:
def __init__(self, client: "RushDB", transaction_id: str)

Properties​

id​

Python
id: str

The server-assigned transaction identifier. Passed automatically via X-Transaction-Id header when you supply the Transaction object to any API method.

Instance Methods​

commit()​

Python
def commit() -> None

Makes all operations performed within this transaction permanent. Raises RushDBError if the transaction has already been committed or rolled back.

rollback()​

Python
def rollback() -> None

Discards all operations performed within this transaction. Raises RushDBError if the transaction has already been committed or rolled back.

Context Manager​

Transaction implements __enter__ / __exit__, so you can use it with with:

Python
with db.tx.begin() as tx:
db.records.create("User", {"name": "Alice"}, transaction=tx)
db.records.create("User", {"name": "Bob"}, transaction=tx)
# auto-commits on success; auto-rolls back if an exception is raised

db.tx — TransactionsAPI​

Transactions are created and managed through the db.tx namespace.

begin()​

Python
def begin(ttl: Optional[int] = None) -> Transaction

Starts a new transaction. Returns a Transaction object.

ParameterTypeDescription
ttlintTime-to-live in milliseconds before the transaction auto-expires. Defaults to 5000 (5 s)
Python
tx = db.tx.begin(ttl=30000) # 30-second window

get()​

Python
def get(transaction: Union[str, Transaction]) -> Transaction

Retrieves an existing transaction by its ID or Transaction object. Useful when the original object is unavailable (e.g. recovered from storage or passed across a process boundary).

commit()​

Python
def commit(transaction: Union[str, Transaction]) -> None

Commits a transaction identified by a Transaction object or a raw ID string. Equivalent to calling tx.commit() on the object itself.

rollback()​

Python
def rollback(transaction: Union[str, Transaction]) -> None

Rolls back a transaction identified by a Transaction object or a raw ID string.

Usage Examples​

Manual commit / rollback​

Python
tx = db.tx.begin(ttl=10000)
try:
db.records.create("User", {"name": "Alice"}, transaction=tx)
db.records.create("User", {"name": "Bob"}, transaction=tx)
tx.commit()
except Exception:
tx.rollback()
raise
Python
with db.tx.begin() as tx:
user = db.records.create("User", {"name": "Alice"}, transaction=tx)
post = db.records.create("Post", {"title": "Hello"}, transaction=tx)
db.records.attach(user, post, options={"type": "AUTHORED"}, transaction=tx)

Recover a transaction by ID​

Python
tx_id = "some-saved-id"
tx = db.tx.get(tx_id)
tx.rollback()