Turso Python SDK

0.0.49 · active · verified Tue Mar 17

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

Install

Imports

Quickstart

Connect to a Turso database using an embedded replica pattern with local SQLite file and remote sync.

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()

view raw JSON →