Turso Python SDK
Python SDK for Turso, a distributed SQLite database built on libSQL. Provides a dbapi2-compatible interface for connecting to local SQLite files, libSQL servers, and Turso hosted databases. The package name on PyPI is libsql-experimental (not 'turso').
Warnings
- gotcha The package name is libsql-experimental, not turso or libsql. `pip install turso` will install a different unrelated package or fail.
- gotcha You must call conn.sync() explicitly to push local writes to the remote Turso database and pull remote changes. Without sync(), embedded replicas remain stale.
- gotcha conn.commit() is required after INSERT/UPDATE/DELETE. Auto-commit is not enabled by default, matching dbapi2 behavior.
- gotcha When using sync_url for embedded replicas, the first positional argument must be a local file path (e.g., 'local.db'), not an empty string or ':memory:'.
- gotcha For remote-only connections (no local replica), pass the libsql:// URL as the first argument without sync_url. Mixing them up causes connection errors.
- deprecated The package is marked 'experimental'. API surface may change between minor releases without deprecation warnings.
Install
-
pip install libsql-experimental
Imports
- libsql_experimental
import libsql_experimental as libsql
- connect
import libsql_experimental as libsql conn = libsql.connect('mydb.db', sync_url='libsql://...', auth_token='...')
Quickstart
import os
import libsql_experimental as libsql
url = os.environ.get('TURSO_DATABASE_URL', '')
token = os.environ.get('TURSO_AUTH_TOKEN', '')
# Embedded replica with local file + remote sync
conn = libsql.connect('local.db', sync_url=url, auth_token=token)
conn.sync()
conn.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')
conn.execute('INSERT INTO users (name) VALUES (?)', ('Alice',))
conn.commit()
rows = conn.execute('SELECT * FROM users').fetchall()
for row in rows:
print(row)
conn.sync()