Skip to main content

Turso is a work-in-progress, in-process OLTP database management system, compatible with SQLite.

Project description

Turso Database for Python

PyPI

Chat with other users of Turso on Discord


About

⚠️ Warning: This software is in BETA. It may still contain bugs and unexpected behavior. Use caution with production data and ensure you have backups.

Features

  • SQLite compatible: SQLite query language and file format support (status).
  • In-process: No network overhead, runs directly in your Python process
  • Cross-platform: Supports Linux, macOS, Windows
  • Remote partial sync: Bootstrap from a remote database, pull remote changes, and push local changes when online — all while enjoying a fully operational database offline.
  • Asyncio support: Built-in integration with asyncio to ensure queries won’t block your event loop

Installation

uv pip install pyturso

Database driver

A minimal DB‑API 2.0 example using an in‑memory database:

import turso

# Standard DB-API usage
conn = turso.connect(":memory:")
cur = conn.cursor()

cur.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT)")
cur.execute("INSERT INTO users VALUES (1, 'alice'), (2, 'bob')")

cur.execute("SELECT * FROM users ORDER BY id")
rows = cur.fetchall()
print(rows)  # [(1, 'alice'), (2, 'bob')]

conn.close()

Database driver (asyncio)

Non-blocking access with asyncio:

import asyncio
import turso.aio

async def main():
    # Connect and use as an async context manager
    async with turso.aio.connect(":memory:") as conn:
        # Executes multiple statements
        await conn.executescript("""
            CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT);
            INSERT INTO t(name) VALUES ('alice'), ('bob');
        """)

        # Use a cursor for parameterized queries
        cur = conn.cursor()
        await cur.execute("SELECT COUNT(*) FROM t WHERE name LIKE ?", ("a%",))
        count = (await cur.fetchone())[0]
        print(count)  # 1

        # JSON and generate_series also available
        cur = conn.cursor()
        await cur.execute("SELECT SUM(value) FROM generate_series(1, 10)")
        print((await cur.fetchone())[0])  # 55

asyncio.run(main())

Synchronization driver

Use a remote Turso database while working locally. You can bootstrap local state from the remote, pull remote changes, and push local commits.

Note: You need a Turso remote URL. See the Turso docs for provisioning and authentication.

import turso.sync

# Connect a local database to a remote Turso database
conn = turso.sync.connect(
    ":memory:",                          # local db path (or a file path)
    remote_url="https://<db>.<region>.turso.io"  # your remote URL
)

# Read data (fetched from remote if not present locally yet)
rows = conn.execute("SELECT * FROM t").fetchall()
print(rows)

# Pull new changes from remote into local
changed = conn.pull()
print("Pulled:", changed)  # True if there were new remote changes

# Make local changes
conn.execute("INSERT INTO t VALUES ('push works')")
conn.commit()

# Push local commits to remote
conn.push()

# Optional: inspect and manage sync state
stats = conn.stats()
print("Network received (bytes):", stats.network_received_bytes)
conn.checkpoint()  # compact local WAL after many writes

conn.close()

Partial bootstrap to reduce initial network cost:

import turso.sync

conn = turso.sync.connect(
    "local.db",
    remote_url="https://<db>.<region>.turso.io",
    # fetch first 128 KiB upfront
    partial_sync_experimental=turso.sync.PartialSyncOpts(
      bootstrap_strategy=turso.sync.PartialSyncPrefixBootstrap(length=128 * 1024),
    ),
)

Synchronization driver (asyncio)

The same sync primitives, but fully async:

import asyncio

async def main():
    conn = await turso.aio.sync.connect(":memory:", remote_url="https://<db>.<region>.turso.io")

    # Read data
    rows = await (await conn.execute("SELECT * FROM t")).fetchall()
    print(rows)

    # Pull and push
    await conn.pull()
    await conn.execute("INSERT INTO t VALUES ('hello from asyncio')")
    await conn.commit()
    await conn.push()

    # Stats and maintenance
    stats = await conn.stats()
    print("Main WAL size:", stats.main_wal_size)
    await conn.checkpoint()

    await conn.close()

asyncio.run(main())

License

This project is licensed under the MIT license.

Support

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyturso-0.4.4rc1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyturso-0.4.4rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.4rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.4rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.4rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.4rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc1-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.4rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.4.4rc1.tar.gz.

File metadata

  • Download URL: pyturso-0.4.4rc1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for pyturso-0.4.4rc1.tar.gz
Algorithm Hash digest
SHA256 ee37caafcac0da2aff0eae49bd86f251bb8db417d2366318f698da1ad98873c5
MD5 dad291f5c9465854ffe218fc85408a53
BLAKE2b-256 1865704c3766f23f9ac66cac5005d719c5fd622a03b589c2a35b0d03f1776cb3

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0a5e799a32867764a9ad91093cb0dc810c964322e2fff18b57cece5855ec8fa
MD5 aebf0a86598d737c923e5a29836165d7
BLAKE2b-256 68526d9f7a6b4b1517ba30fc226f06ba6e901e853cc9b9acb985179870f34f02

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2f6fedfb6d718650d28d7084eb1d3d0a12344d0e5b1ee20b0c1c71243e1f7af
MD5 47b10a9026dd4c2aa1d80c073857faf4
BLAKE2b-256 28285bc5268f71c8a42f6dfb620a66078cefcd8e44fd639ded6f1a1786c840b1

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 143c7b80bb9b5cec5c16e69d82313da744e78a4daf3cd4294dbaa265908232ec
MD5 1f08ee83582640f8c6aa8a4654250ce6
BLAKE2b-256 fa14c4b7c0bf771ed5e0464e24537fb03d55e4bb68daac8b44fb6445f1b05c41

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b414f880e38a9bd2d1eed4673417671b802f575bc36f8365ce4a508c506b8c43
MD5 21ff3754b247798393a9db3cc73216dd
BLAKE2b-256 104062f9fd222590fbe4bacefda94640f7c770ac3a137c2c5f6141ae0799a68a

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95eac141b8534b9abd92f5b03675a3df889ed419221b10aa283e308df8ab9f08
MD5 b909e2d524b6be2c451784a90188c68a
BLAKE2b-256 7d58b4d8c4cec60c344bb5d6385f42748cf34cf0fc760c584f1af8b232a9246f

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14222cbf21b93233e9420d2af7209155e49a1db2732c3fba2f2e1362be0d9a1e
MD5 e565fd32a70c552d0b2a4619a8db5002
BLAKE2b-256 4729a8649012dae9f345fd389d355540a9723972ef80149f9fcf26845112a8ae

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9682cbdcaa3c473a3817c603b7940894c7c94055f64ec87f50337a19be562f2
MD5 e34cab53771c0d245e342e5061a5d825
BLAKE2b-256 9af8fd5bebccbbe98087b02f4a8901f1d36861f81bb15e9f32c932b765ce0da8

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2cc2260ca605a97de434428663e9cde732564629c6a76e46a22ce32961b168fb
MD5 951c37498026b2969cad133f4b4e6f34
BLAKE2b-256 5f6c646e3d84a991bc0b2cc9fb66155b54ace7fd6015444de502305bfb5577fe

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97c04837530d809f6f7b365a22254fdb8de2b0ecce009ff2278974517208c841
MD5 40bf11a62e685d6e977cd4732eb869ad
BLAKE2b-256 155c2549f9d63914e3e994f9210e42aeb1b4b66e42b288d0b0d10e72ee8fc742

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69e8d3b38cf2f38ddab75a22b6861b1666b315eba9317fcba6e2c1201dc2b180
MD5 21ddadeb1344295f5363f5a95142a3b0
BLAKE2b-256 381f193f143536bce9a5d14d178f142d3b6f5e931cae386f476be4e3100b87a1

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c39f02d522c9113f7fc420d77f6fbc43f048800c319ecb3701b804f7bde5fb1
MD5 2d395b4fbe37454f219bf1f42f51053f
BLAKE2b-256 e05f328946909e10e59d9b2865e7692debf0a176874312b8d208e8f61282fa1a

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62967f607a8500fb5faebf8610a517c873e403ff166ed98c746bf796bb606282
MD5 a2f4c473b69dfe3219f1d3569233b1ae
BLAKE2b-256 464567861a58fe9fa59c366d4f89b6728d9295eee88a9154ab0c6a5a07820399

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page