type_bridge.session¶
session
¶
Session and transaction management for TypeDB.
Database
¶
Database(address='localhost:1729', database='typedb', username=None, password=None, driver=None, *, http_port=DEFAULT_HTTP_PORT, server_version=None)
Main database connection and session manager.
Initialize database connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
TypeDB server address |
'localhost:1729'
|
database
|
str
|
Database name |
'typedb'
|
username
|
str | None
|
Optional username for authentication |
None
|
password
|
str | None
|
Optional password for authentication |
None
|
driver
|
Driver | None
|
Optional pre-existing Driver instance to use. If provided, the Database will use this driver instead of creating a new one. The caller retains ownership and is responsible for closing it. |
None
|
http_port
|
int
|
TypeDB HTTP API port used by the connect-time version gate probe (default 8000). |
DEFAULT_HTTP_PORT
|
server_version
|
str | None
|
Exact TypeDB server version to use for connect-time validation instead of probing the HTTP API. Use this for gRPC-only deployments with the HTTP API disabled. |
None
|
Source code in type_bridge/session.py
connect
¶
Connect to TypeDB server through the Rust runtime.
If a driver was injected via init, this method does nothing
(the driver is already connected). Otherwise, initializes the cached
Rust database handle. Direct access to the external Python TypeDB
driver remains available through the driver property.
Source code in type_bridge/session.py
close
¶
Close connection to TypeDB server.
If the driver was injected via init, this method only clears the reference without closing the driver (the caller retains ownership). If the driver was created internally, it will be closed.
Source code in type_bridge/session.py
__enter__
¶
__exit__
¶
__del__
¶
Destructor that warns if driver was not properly closed.
Source code in type_bridge/session.py
create_database
¶
Create the database if it doesn't exist.
Source code in type_bridge/session.py
delete_database
¶
Delete the database.
Source code in type_bridge/session.py
database_exists
¶
Check if database exists.
Source code in type_bridge/session.py
transaction
¶
transaction(transaction_type: TransactionType) -> TransactionContext
transaction(transaction_type: str = 'read') -> TransactionContext
Create a transaction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transaction_type
|
TransactionType | str
|
TransactionType or string ("read", "write", "schema") |
'read'
|
Returns:
| Type | Description |
|---|---|
TransactionContext
|
TransactionContext for use as a context manager |
Source code in type_bridge/session.py
execute_query
¶
Execute a query and return results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
transaction_type
|
str
|
Type of transaction ("read", "write", or "schema") |
'read'
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |
Source code in type_bridge/session.py
detected_server_version
¶
The server version detected by the connect-time version gate.
Returns the version string (e.g. "3.12.0") when known. None
only when the connection was established through the band-7 gRPC
fallback, where the server cannot report its version — supply
server_version= at construction for strict validation there.
Source code in type_bridge/session.py
check_schema_annotation_support
¶
Version-gate schema DDL that uses @doc/@meta annotations.
Raises the versioned error when the TypeQL uses schema annotations (TypeDB 3.12+) and the detected server version predates 3.12. When the server version is unknown, the DDL is sent as-is and the server decides.
Source code in type_bridge/session.py
supports_given_stage
¶
Whether given rows can execute on the active connection.
This requires both TypeDB 3.12+ syntax support and a negotiated band-9
provider. It remains False when the server version is unknown or
when a 3.12 server stays on the safe band-8 discovery connection after
a band-9 upgrade failure. Bulk operations consult this before dispatch
and use their per-row fallback when it is False.
Source code in type_bridge/session.py
execute_with_rows
¶
Execute a given-stage TypeQL query over input rows.
One compiled pipeline runs over every input row; the rows travel through the driver API instead of being interpolated into the query string, so user-supplied values never touch TypeQL text. Requires a TypeDB 3.12+ server; on older servers this raises the versioned error from the feature gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL starting with a |
required |
transaction_type
|
str
|
"read", "write", or "schema" |
required |
variables
|
list[str]
|
given variable names without the |
required |
column_types
|
list[str]
|
TypeQL value type names aligned with |
required |
rows
|
list[list[Any]]
|
input rows, each a list of primitives in column order (temporal values as ISO-8601 strings) |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries (one per pipeline output row). |
Source code in type_bridge/session.py
get_schema
¶
Get the schema definition for this database.
Source code in type_bridge/session.py
Transaction
¶
Wrapper around TypeDB transaction.
Initialize transaction wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tx
|
Transaction
|
TypeDB transaction |
required |
Source code in type_bridge/session.py
execute
¶
Execute a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |
Source code in type_bridge/session.py
commit
¶
rollback
¶
TransactionContext
¶
Context manager for sharing a TypeDB transaction across operations.
Source code in type_bridge/session.py
execute
¶
Execute a query within the active transaction.
execute_with_rows
¶
Execute a given-stage query with input rows in this transaction.
See :meth:Database.execute_with_rows for the argument contract.
Requires the Rust backend on a TypeDB 3.12+ connection.
Source code in type_bridge/session.py
commit
¶
rollback
¶
manager
¶
Get a TypeDBManager bound to this transaction.
Source code in type_bridge/session.py
ConnectionExecutor
¶
Delegate that handles query execution across connection types.
This class encapsulates the logic for executing queries against different connection types (Database, Transaction, TransactionContext, or proxy equivalents), providing a unified interface for CRUD operations.
Initialize the executor with a connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection
|
Connection
|
Database, Transaction, TransactionContext, or proxy equivalent |
required |
Source code in type_bridge/session.py
execute
¶
Execute query, using existing transaction or creating a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
TypeQL query string |
required |
tx_type
|
TransactionType
|
Transaction type (used only when creating new transaction) |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of result dictionaries |