Connection is the primary object in the turso package. Obtain one by calling turso.connect().
turso.connect(database, **options)
Opens a Turso (SQLite-compatible) database and returns a Connection.
Path to the database file, or
":memory:" for an in-memory database. The file is created if it does not exist.Default transaction mode used for implicit transactions. Accepted values:
"DEFERRED", "IMMEDIATE", "EXCLUSIVE", or None (autocommit-like behavior without automatic BEGIN).Comma-separated list of experimental features to enable, e.g.
"views,encryption".VFS backend override. Available:
"memory", "syscall", "io_uring" (Linux only).Encryption configuration. Requires
"encryption" in experimental_features.Connection
connection.cursor(factory?)
Creates and returns a new Cursor object.
Optional callable that takes a
Connection and returns a Cursor subclass. Defaults to the built-in Cursor.Cursor — see Cursor for the full method list.
connection.execute(sql, parameters?)
Shortcut that creates a cursor, calls cursor.execute(sql, parameters), and returns the cursor.
SQL statement to execute.
Bind parameters.
Cursor
connection.executemany(sql, seq_of_parameters)
Shortcut that creates a cursor and calls cursor.executemany(sql, seq_of_parameters).
A DML statement (INSERT, UPDATE, DELETE, or REPLACE).
An iterable of parameter sequences, one per execution.
Cursor
connection.executescript(sql_script)
Shortcut that creates a cursor and calls cursor.executescript(sql_script).
A string of one or more semicolon-separated SQL statements.
Cursor
connection.commit()
Commits the current transaction. If isolation_level is not None, a new transaction is begun automatically after the commit to maintain DB-API 2.0 semantics.
connection.rollback()
Rolls back the current transaction. Any changes made since the last commit() or rollback() are discarded.
connection.close()
Closes the connection. If autocommit is False and a transaction is open, it is implicitly rolled back.
Properties
| Property | Type | Description |
|---|---|---|
connection.in_transaction | bool | True when a transaction is currently open. |
connection.isolation_level | str | None | Current isolation level setting. |
connection.autocommit | bool | "LEGACY" | Autocommit mode. Set to True, False, or "LEGACY" (default). |
connection.row_factory | callable | None | Optional factory called with (cursor, row) to produce custom row objects. |
connection.text_factory | callable | Callable used to decode text values. Defaults to str. |
Context manager
Connection implements the context manager protocol:
Exception hierarchy
Turso follows the DB-API 2.0 exception hierarchy:Connection object (e.g. conn.IntegrityError).