# Lesson 6.3: Transactions

## [](#_opening_transactions)Opening transactions

With a connection established to the server via a driver, open transactions directly against a database. There are three transaction kinds: `READ`, `WRITE`, and `SCHEMA`.

```python
from typedb.driver import TypeDB, TransactionType, Credentials, DriverOptions, DriverTlsConfig

DB = "bookstore"
address = "localhost:1729"
credentials = Credentials("admin", "password")
options = DriverOptions(DriverTlsConfig.enabled_with_native_root_ca())

with TypeDB.driver(address, credentials, options) as driver:
    # Read transaction
    with driver.transaction(DB, TransactionType.READ) as tx:
        pass

    # Write transaction
    with driver.transaction(DB, TransactionType.WRITE) as tx:
        # mutations...
        tx.commit()

    # Schema transaction
    with driver.transaction(DB, TransactionType.SCHEMA) as tx:
        # define/undefine/redefine...
        tx.commit()
```

The transaction takes a database name and a transaction type. Use a context manager to ensure closure. Write and schema transactions must be committed to persist changes.

## [](#_behavior_and_lifecycle)Behavior and lifecycle

*   Read transactions: read-only; lazily stream results.
    
*   Write transactions: buffer mutations; commit persists or rollback discards.
    
*   Schema transactions: exclusive with other write/schema transactions for a database.
    

Transactions are short-lived atomic units of work and provide ACID guarantees up to snapshot isolation. See [Transactions](../../../core-concepts/typedb/transactions/index.md) for details.

To get a deeper understanding of using TypeDB transactions - including concurrency, configuration, and best practices - see the driver-side [Transaction Concepts](../../../core-concepts/drivers/transactions/index.md) page.

[Managing users and databases](../6.2-managing-users-and-databases/index.md) [Executing queries](../6.4-executing-queries/index.md)

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/academy/modules/ROOT/pages/6-building-applications/6.3-transactions.adoc) Edit this page on GitHub.