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, tls=None, tls_root_ca=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
|
tls
|
bool | None
|
Explicit TLS policy. |
None
|
tls_root_ca
|
str | PathLike[str] | None
|
PEM root-CA path for an explicitly enabled TLS connection. A root path never enables TLS implicitly. |
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, the owned Python driver closes
first. If that close fails, the complete
transport remains attached for a released-style retry. After it
succeeds, embedded-Rust and snapshot cleanup are attempted. A Rust
close failure is logged and masked to preserve the released Python
Database.close() contract; snapshot failures retain their normal
error behavior.
Source code in type_bridge/session.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
__getstate__
¶
Preserve released pickling for pristine connection configs.
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_database_outcome
¶
Create the bound database and return a race-normalized outcome.
Source code in type_bridge/session.py
delete_database
¶
delete_database_outcome
¶
Delete the bound database and return a race-normalized outcome.
Source code in type_bridge/session.py
database_exists
¶
Check if database exists.
Source code in type_bridge/session.py
inspect_database_pair
¶
Inspect the managed database and its package-owned journal as one pair.
Source code in type_bridge/session.py
inspect_database_pair_controlled
¶
Inspect the managed database pair under explicit execution controls.
Source code in type_bridge/session.py
plan_database_delete
¶
Create a single-use, pair-aware managed database deletion plan.
plan_database_delete_controlled
¶
Create a managed deletion plan under explicit execution controls.
Source code in type_bridge/session.py
transaction
¶
transaction(transaction_type: Enum) -> TransactionContext
transaction(transaction_type: str = 'read') -> TransactionContext
Create a transaction context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transaction_type
|
Enum | 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.3") when known. None
means the negotiated connection path produced no authoritative server
identity; supply server_version= at construction when strict
identity validation is required.
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
¶
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 |