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.0rc5.tar.gz (1.6 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.0rc5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp314-cp314-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp313-cp313-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp312-cp312-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp311-cp311-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc5-cp310-cp310-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc5.tar.gz
Algorithm Hash digest
SHA256 4f3b30a7847b0f8842927f2e467faf30104079e790ac74529dd6879e209355c8
MD5 210a1ef423bfc99baaec0e15d31383b2
BLAKE2b-256 7b07f3f4ae13e806c2b6a2ff1391797ae9a055c2c198ac223e02ccb88b5df45c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8233a59db84d767822e59abcca833277d044b6cc1010b00c29040f713955bfd2
MD5 8b89548a49fe16c2b2fcb4430e4cd691
BLAKE2b-256 ac6333fcb5621f8c9b65e02c653d3e7ca9da5b410174aff58ff09d839f2dd2c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17f330ccd16b54a843d521897ae19351e7088070fd00207d2393082ff4856ef0
MD5 0cff8f8b1b17bed18c99d4acb7f9679c
BLAKE2b-256 3dd123498ec8e508c6a62f47c88f3de7cb44791638fccb5099d949a28e996b6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b563fcd55aa54908d04964a0b1406408225aabca26eebed0be449ab26c866b52
MD5 0ab896f860c19966a4ba633ba32b80c9
BLAKE2b-256 26c2d7f64ce16670208359cc11babc095f76c1ee7c882e7ab6be7c6d22b41c25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2553c38aaebe4b2d29beeb4326bb7f16cb83c2b0b07f40728286a6104a166ba3
MD5 c908b96ab8562ca71680e652c1d9e91c
BLAKE2b-256 d4036cb3394efc8cd99c0940251ab2c383f87262996117d3858542943caa84f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 315f2c393d0825f526fc4da46d78bfa48bf8b2853657c16c0137cd8a34b894d4
MD5 df17a29c76d40bb04c137600d639fc6b
BLAKE2b-256 f9b13b3f0e0f46da8907fa3895eb0705d1fac1525a7a15cb07683720771cc254

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb761e27f25e48f3d74f3504cad728ece49834982d64a43f941f10f98f883732
MD5 bd341efd0a932b2535335e993e75200a
BLAKE2b-256 ba2e7ffb069f442202d105f47f2eab4f1d4f2bc5394b64c85dfc58b087c6e8d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91c2308fb724b9cc31ecfe942933886f0e59034b7b08f1c50944d54bba03e936
MD5 e26433453a03429dcca1dc87655c3182
BLAKE2b-256 ce90bd0b2841ba4659f9c460f3ba292eae78b043abf10c29e73c2ec64b54e4ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c8f988d4939b64088201f203fec742684f3d144b8cc5de6f7118beb3f386217f
MD5 5a1c2ce7454c2baf7de7e5b6dd7d2f95
BLAKE2b-256 32430c750abb46ac87d0455b5831b2175b7cb0ef3520fd5a7298068f6e790eaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 674a35fadea834779997f89b5bd4dc91120c54f2294c64b25fd8a0525e7fc88c
MD5 1e91b35075827aa9604d7a6b66b689b5
BLAKE2b-256 38224b5e57acd13c8c07ad08149cfacaa29550468ff7d4b2720a6b0a9940b6f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3f82896dd17501043d38b4371752a39090c74f9e564ec0c93f9a90ec7d9550f
MD5 27520e3788b8a0886da5536e5b436f61
BLAKE2b-256 2dd6fea05a7ff56c7fe1985fff90ca1506fe8e2a576e91eacf45fd62ee6bd763

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03792c74397712ca17e2a733b4ecd685a3a773be90f2dc8a8c31f24482496ea3
MD5 bfe5cbf2e25b99b1fc35f77275f1cddc
BLAKE2b-256 ed63cbd0c274868c5b282005e201e0976f403244057522af82a04d5d71a36fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6925e16e3a8b383253dd7d673622870f1451db1a149ccbe6c88785a0a759539
MD5 38beede1b5992c9ef525a5b3a06b2e63
BLAKE2b-256 09ce4530c31fe58afbeafaf6f18defa9f6d93559d54e7944610afb2260a8fa87

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