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.0rc17.tar.gz (1.9 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.0rc17-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc17-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc17.tar.gz
Algorithm Hash digest
SHA256 fc1d263ce48aafb62fcb9f5008fb82e64e84db487f7a8ee47bae8176a646876c
MD5 f6e1bf539adf2535fc9d72168a492885
BLAKE2b-256 772632f98598f0e25e09ddaaf2808ee1249065414b7b84b0701f4e95e6eea6fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cca591983eb7c1ffe3dcdb94a5bc891801f5cf37f3e97e5ce793dc7a7a371c56
MD5 ddf99d910eacad6d9f0abf88c7eb7781
BLAKE2b-256 32fa2557b060f13c5832307da4e7cf7af9154931844642eda3a910bf33c6753d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98b76a6d940193d19cbbcce8c40b22da2f317ef2a5428bf5eb241738ab97ccb5
MD5 485c5a6c9302ff95737cfd87b31d91e9
BLAKE2b-256 7526b779328c3d41b5428814c663ca9ac1a1298d43382c228185508554fbdb0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b32aacbe9bd21c724c215ee67399ba88f5c6fa9528bcf5a4a625ba59c771b7f
MD5 c93c6d75a82340dd5ea0024005f2934b
BLAKE2b-256 78253bed7745d346223df23d23ea6abd3d63b2600c1e16159ce1583d8b847dfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14b6a952b5e9357fd9eceabc574adcb471ff13c02733e3cb9e839ca7fc957c4a
MD5 295f342f88c5fabe5fcda7ba2981b181
BLAKE2b-256 109252d9b02e8a1478b0ff1f58790fc0100232f225d6e2d412cef27aa582ee65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfa22c04891162df2e316b7e70ef6a2f48db3c0d60903abbea96bf0660a10d8c
MD5 347bb4cddf2788a14b258d4ff4722719
BLAKE2b-256 693e446afde7b6eb9b58c58f143cd497f8d5b335c29f130ec06eb96d71f89aa2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14a9c33deea03401f03a0167fe206845a1f7937f02b1d212bddc54df54671b26
MD5 aaf9abb385e4b4705e38e121c33afacc
BLAKE2b-256 0e62e771a4625fbfa324920cf7ba2f36298795b1b3e63577abc438ba5a94e5f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 08cf2ef03cb2373248638db371401c194c3d384b17e1723de095a7f7a612c9b2
MD5 fdf09fa8e6303acfcba3552261af00a3
BLAKE2b-256 2079d08f0ef540d10c634ff2a97b5eb81ae8d95b5df14cdba2c1a7d00adc4d77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70c6ea3fb32386db244699490549c3b18f6f83994bf37ed3e813d41e66c96280
MD5 1896f2a4b335e367e5640bb62297c7a4
BLAKE2b-256 ba82f6092c2c3bdf6787fcba662223473f0d1a104caa4e959e9aeb75d4684952

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b9c320244d128ac1fda4871d1a3a8a518bec0cb8075a0c2d066325d5869de51
MD5 dfda64c4ff8420c4138163bfec8b8b94
BLAKE2b-256 2205753488ea791d87ab754cbbd0f9d45136af67d80baefb2c014fef3ffea230

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28df8645551ace2a3f91420e7979dd2203989cef91ea5f2fa6d96bddf14bf30c
MD5 5fd9ee5ad0df0950da9053267db2a8e1
BLAKE2b-256 aea3ec66b05f2fe8289c6e5eb3fc75ce1ed935b56dae0a610d7a923fbfd3068c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c141c9c221eb5dc2b3c20207acc47fe7158ff14867fa961614841f79121866cb
MD5 021e403affa155811195f4dd1b888dc3
BLAKE2b-256 8cd9104cbfae7fb18e66a318ff34f6fc4b9d3e9cd24024d518167d99e81686be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec0aa6b0dde72ad3f09b27cc294324082781759c2ba4b11c1b4df1ea56b24c6e
MD5 f6de367445a0dc55c3017cf19fd66c87
BLAKE2b-256 555e63412d0dbe9f2e46ae391d65ce759b9e9f46b2e5fa8856ece6619358426e

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