Skip to main content
The turso Python package provides a PEP 249 DB-API 2.0 compatible interface, closely mirroring the built-in sqlite3 module.

Installation

pip install turso

DB-API 2.0 module attributes

AttributeValueMeaning
turso.apilevel"2.0"Implements DB-API 2.0
turso.threadsafety1The module is thread-safe; connections are not
turso.paramstyle"qmark"Positional ? placeholders

Quick start

import turso

# Open (or create) a database
conn = turso.connect("app.db")

# Create a table
conn.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)")

# Insert rows
conn.execute("INSERT INTO users (name) VALUES (?)", ("Alice",))
conn.execute("INSERT INTO users (name) VALUES (?)", ("Bob",))
conn.commit()

# Query rows
cursor = conn.execute("SELECT id, name FROM users")
for row in cursor.fetchall():
    print(row)  # (1, 'Alice')  (2, 'Bob')

conn.close()

In-memory database

Pass ":memory:" to open a transient in-memory database:
conn = turso.connect(":memory:")

Context manager

Connection implements the context manager protocol. A successful block commits; an exception rolls back:
with turso.connect("app.db") as conn:
    conn.execute("INSERT INTO users (name) VALUES (?)", ("Carol",))
# Connection is committed here (no exception)

Pages in this section

Connection

Open a database, commit or roll back transactions, and run ad-hoc SQL.

Cursor

Execute statements, bind parameters, and fetch result rows.

Build docs developers (and LLMs) love