# before.py
import sqlite3
conn = sqlite3.connect("local.db")
cur = conn.cursor()
cur.execute("SELECT * FROM users")
# after.py
import libsql_experimental as libsql
conn = libsql.connect(
"libsql://your-db.turso.io",
auth_token=os.environ["TURSO_TOKEN"],
)
cur = conn.cursor()
cur.execute("SELECT * FROM users")Without changing more than an import, you can take your sqlite3 code, point it at Turso, and get concurrent writes, embedded replication, and unlimited databases. This page shows where Turso fits and how to start.
libSQL is a fork of SQLite with a wire protocol. The Turso Python SDK implements the same Connection and Cursor interface as sqlite3, so almost any sqlite3 code works without changes.
# before.py
import sqlite3
conn = sqlite3.connect("local.db")
cur = conn.cursor()
cur.execute("SELECT * FROM users")
# after.py
import libsql_experimental as libsql
conn = libsql.connect(
"libsql://your-db.turso.io",
auth_token=os.environ["TURSO_TOKEN"],
)
cur = conn.cursor()
cur.execute("SELECT * FROM users")Take all your sqlite3 code that runs on one machine. Here is what you get when you give it room.
01
Concurrent writessqlite3 serializes writes through a single process. Turso's libSQL uses optimistic locking so multiple workers, threads, or processes can all write in parallel.
import libsql_experimental as libsql
conn = libsql.connect("libsql://your-db.turso.io", auth_token=token)
# Optimistic concurrency: multiple workers write in parallel
conn.execute("""BEGIN CONCURRENT""")
conn.execute(
"""INSERT INTO events (user_id, action) VALUES (?, ?)""",
[user_id, action],
)
conn.execute("""COMMIT""")02
Parallel querieslibSQL supports async I/O natively, so your async Python apps don't block on database calls.
import asyncio
import libsql_experimental as libsql
async def fetch_user(user_id: int) -> dict:
conn = libsql.connect(url, auth_token=token)
cur = conn.cursor()
await cur.execute("SELECT * FROM users WHERE id = ?", [user_id])
return cur.fetchone()
# Run many queries in parallel without blocking
async def main():
results = await asyncio.gather(
fetch_user(1), fetch_user(2), fetch_user(3)
)03
ReplicationEmbedded replicas sync to Turso Cloud in the background. Reads hit local storage; writes propagate to the cloud replica.
import libsql_experimental as libsql
# Embedded replica: reads hit local storage
conn = libsql.connect(
"local-replica.db",
sync_url="libsql://your-db.turso.io",
auth_token=token,
)
# Pull latest writes from the cloud
conn.sync()
cur = conn.cursor()
# This read hits local disk, not the network
cur.execute("SELECT * FROM sessions")04
Multi-tenancyProvision thousands of databases from a single API call. Each is isolated, lightweight, and costs only storage when idle.
import turso
client = turso.Client(
org=os.environ["TURSO_ORG"],
token=os.environ["TURSO_PLATFORM_TOKEN"],
)
# Provision a fresh database per user or tenant
db = client.databases.create(
f"tenant-{tenant_id}",
group="production",
schema="tenant-template",
)The Turso Python driver exposes a DB-API 2.0 interface, which means any library that works with sqlite3 can work with Turso with minimal changes.
Full ORM support via the DB-API 2.0 adapter. Use SQLAlchemy Core or ORM as-is.
Native async support so your FastAPI or Starlette app stays non-blocking.
Use the Turso datasource adapter for Prisma to keep the DX you already have.
Any library that accepts a sqlite3.Connection-compatible object works out of the box.
Also works with Django, Flask, SQLModel, and any DB-API 2.0 client.
“We didn't rewrite SQLite in Rust to be fancy. We wanted to support modern development needs while preserving SQLite's legendary reliability.”
Turso engineering team
libSQL is MIT-licensed and developed in the open at github.com/tursodatabase/libsql.
SDK releases track the libSQL release cycle. Changelogs are public.
Works on Python 3.8+. Install with pip or uv.
pip install libsql-experimental
import libsql_experimental as libsql
conn = libsql.connect(url, auth_token=token)uv add libsql-experimental
import libsql_experimental as libsql
conn = libsql.connect(url, auth_token=token)100 databases free. Unlimited databases on paid plans. No schema changes required.