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.4rc3.tar.gz (1.5 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.4rc3-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.4rc3-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.4rc3-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.4rc3-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.4rc3-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.4rc3-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.4rc3-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.4rc3-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.4rc3-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.4rc3-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.4rc3-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.4rc3-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.4rc3.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.4.4rc3.tar.gz
Algorithm Hash digest
SHA256 837fb33923b70074a93d50d4296cecc96dbbf4104e74ce4dc25c81654baea7d9
MD5 aada3ea8990bac78af1330e583c2c83b
BLAKE2b-256 d8c6fb10c13f191a7ed256874cde221063ec779fdd0f85e446b1e4b69be0f74e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05d6be0f992f17267fed424c9ba4a963e6289f707848af5ecb7178384956a4f6
MD5 9a01a035463c5601aa69f84fc4c34af8
BLAKE2b-256 c5c57180f16bf5b18edd346c7d01acdcc192eb673d9ac54e26fd21b426fe84e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6b761680787d7fca0c28c973ebd7efe2ec26e48e3403c04c905b552cc035543
MD5 19783dbcde5e4f2139cfd2863c0b8aa4
BLAKE2b-256 aa618d91f59ebc6ffe440226154e9949e731439429f14ad246c219611b6ffa54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c4392794728a2c621e8290d1d07ef652584472da8c7ffcb88fe9301e4fbab8dd
MD5 c5d634ee1568b7dbe49a1759455a09c1
BLAKE2b-256 800973aceeddaa983a1a9c5be2ced5e18edc697c86259cc8859168cc2872a2ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 769289a16233291271dbe472375e2a44ad34b7fe0f727b5e301e52bba4c787a7
MD5 2093f38cd12195291fb92bbbc4a57f6f
BLAKE2b-256 cf02d9f6b20a27c31a78b02b07f5fdd10cbc63fa33a4101f39b7366749a37931

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82ff8afe7061066aea120c6223795f394a8f0ea9f995b95db6f6029b600c1066
MD5 80edabac49dbed6d66c09ca4920ca698
BLAKE2b-256 4597d705e250e27d5654cae376693ce09e76d58a57e20c115d1284ae31877d43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73bf70fb59db0abb9653f3ba99a9df08533eb4ded3ca89b4141d8ca60209ae98
MD5 0a97595348fa76d804b69fa71c491cf9
BLAKE2b-256 04ee24d04f835362618fc96ce02e57dd68372db5a130a3414778df6063a368b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82aa9f118fbfc0f5d8c8294f4b36b5c86944fbfbcbadbc4c7400fa617df72b5b
MD5 fd40424ff6f1923b68f6da0f4a2cef54
BLAKE2b-256 c6bf6eaf1de97634c2948a48e8aa0881457a05e121caf8fb31102f6ade05421f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6b26f9c6d13bec7bfa9f642eb311cf39f1dc574fe3044af732ae456f483554d
MD5 1604b07862a10e57503af9a36723bac0
BLAKE2b-256 41e25f240e2e1769b7523b976210dffc5b4a2f3360508f951efea155958dcc43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54d1910c53e2ef93c45f45602b7ca6f0ec8600c9c98dd9f872bebc1f6947cc43
MD5 b113dc3e8566326701b0fbcc475e9d1a
BLAKE2b-256 87622a2d81b03bb4fb317ba23f223d2c8e2c1719510c268564315905a4f4cf3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54a34770129f187d5a2d05abce6897d5e47de877d871f0312aaeda7547c289b4
MD5 0b5c63c6ce18a1c0ba475cc6af223b6e
BLAKE2b-256 56ef113b49636d4bb2c436e3318d66bfb92a0e6be386c153b066602a12daaadb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c716f0798df9bc82d9435fae666861cab7795912de78ee9f62d9d25da49a9038
MD5 cf8c1c69bd5246acb96f8f9920029504
BLAKE2b-256 e72eaa0216190587a60748a40616681e8fbf56fba6310b52fe5539ebe76cf5d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db74b4294ce96d7a03f14143f9c7efee64f2906fe4d2ee4e619102d211079d83
MD5 a175ba1c4ff30521cfd67d74efca7ede
BLAKE2b-256 e097ab11623c0c44e4c1603d50427f4d3445c3ae8c1039702d6309b8e74aeba0

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