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.5.0rc12.tar.gz (1.8 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.5.0rc12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp314-cp314-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp313-cp313-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp312-cp312-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp311-cp311-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc12-cp310-cp310-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.5.0rc12.tar.gz.

File metadata

  • Download URL: pyturso-0.5.0rc12.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.2

File hashes

Hashes for pyturso-0.5.0rc12.tar.gz
Algorithm Hash digest
SHA256 69c4a0d1cc63a1411208831ee31d3589de5ffee40e3128763d352fafd526fe67
MD5 769d8c44bdf734cd51a21c5c49bb58a3
BLAKE2b-256 9e772882b9a22dd461766070dbb4e1c0804dd7f3fd7fae31bccc3a55810c713d

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5e8e2be459defea1f02f1e9cbb113480697c9517025cb446a44868959cf9c3d
MD5 c76b7e21c6c99e69c4672a9fa10a60dc
BLAKE2b-256 3472e8e4ae7aed22e2de9d4a2b1ea26882270f477a9b7b75907ea232e55ac946

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 330a6073368956e930fe8f9406810d8e18b983c021940182eb8cbad2bb0192fd
MD5 d8278f2d5b87f4f61abb7a52abfe3733
BLAKE2b-256 e533801b77fa68a499e7bdb10ad2ec0f27802423684097ebde0383ab9293d2d1

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6957f200de8d153766619d3f07581b431c484ed1deb30425bb1449514a8bf664
MD5 8de521fec708583efa9aa7a6a960e73f
BLAKE2b-256 05646f54f92ef7043c820925d28d7c2f69b544255372be0125c2e0a0c84a5731

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4432b4fbd475a21154d120cb230fb4da726a73956dc7b5c07dbd0bd7162cf592
MD5 9403b376261624f408e5b468eb5326fc
BLAKE2b-256 8242a5755c0601f7070742dab0c97ebae751b9f617a587344e6d423d08bd6a1c

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25e5ff93c02251d4d0ed8cfaeb1a724a7a97ad11e38efd6138a91565d6c8f652
MD5 6e94a7d87e35808443d5b12b98812048
BLAKE2b-256 6b595eb6a3b5fd4a8f5824d32d55e6022c67f36809ad1d72542c26acef1c7acd

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0d3a1605f7a7bb685b33325aff387f1ad19764b7d9d031af7ac041e8df38509
MD5 c581ccc9852781cdcc47c19610c58645
BLAKE2b-256 e03bd62a0db8070d92f2b2e15d2ef18950acb4cd82c6c24c7faad40877c749e8

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7334a597d3b1ed9003d0bf9d57c420c6e02ff76fb77e4d0f36027d79b1a38a2
MD5 f37115fbeaa44cc92b2b6cce15157ad5
BLAKE2b-256 f3a76b3a025413d9ca4f04f8f304d8ebbd89d585ca5522421e5d599c76961a68

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c235740bfb04295f5337426090dcfd06fbe6620b53930cb4e4a1f4821dbb8e2
MD5 1bec8113335e93d8bca1af9d597ac358
BLAKE2b-256 4915d362e5f8f72e868693e4edec9827c25ff3c231df1545af6c3099c40e9dd9

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 741f195db2672a517d64c496d1de1d32705515f4a22b18715b87c638603299e9
MD5 3f3e5edc1d0520526bc7f0f504fee677
BLAKE2b-256 cd5409ab064c859ed757deb6004b6d40c92a6a9ed6cefd96da9430807dfb66ce

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17fc9a95801b99f006beb7d3338f7a933d223746847e93478dc8b77191059f95
MD5 cc3a63eb95bda9f5c9e493d1a1e16b34
BLAKE2b-256 87effb3235466d0c643458f4f84375ff0f5e2ee4ad7ec20a7f5318ba98118be6

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c219a29ea4bf780088a6a8b0aa77b44570f08a3bebc5cdfc7c34a27e68d3e9dc
MD5 e1333e2c730fb295444a05c806d258f3
BLAKE2b-256 03ff45b889bcfb389d598070e338135f38e924688c527b11810b4e6af4d07965

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d082760c54e0b05614109e607eee1945bd659be9fa40e2470be01fc30784acb
MD5 5df03f94e627c1c655c431236683d603
BLAKE2b-256 156af24e8baaff08831c614889f8bbdfafb200117bfe15871f4aff83686a90ac

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