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_opts=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.0rc16.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.0rc16-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc16-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.4.0rc16.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.4.0rc16.tar.gz
Algorithm Hash digest
SHA256 4f06f566646f9ae4770197a5facecfb84044b150816db739825c3089cec7ab1a
MD5 e8a691e506890620446386f147e8eab3
BLAKE2b-256 506849785918ae6d3586cc6a6b3280f0c489456419d6ec1807ad00e52ce17329

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d28a2276e314864c4cead7a2a857452b86a5c411037f64e004b4c68bc0d1a198
MD5 19a756181525bc58735325343e1431d3
BLAKE2b-256 4cfa142ea68d179d2470a5aff923ffd5c8cfe9f8c5be9a07c9606db0e2a024a5

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1ba65be59a81c03d6357a323aedff475646c793c393847c976eb3c909028cea
MD5 e568dad2f6d48e13c541ad2d82113df2
BLAKE2b-256 c95924cde68873b4e7041a7d13467709cc89f29a1afa28fcf931c1679b62d430

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a3986147fb9fbf8745105c60caf643c1de87e08ce416a801062708b1e9fac34c
MD5 54ffe644f193ed3fb323892e5ac18cb0
BLAKE2b-256 0f85df87b4b2162ef9a5724ba4a384cd8b598350289f5e1ec076d1b8be362c87

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd380ad20565ea5313fed5cd27e2012964644602aee134be29c40e39d0b4ca45
MD5 69484982ef0bb70a3df7f4bf615c70bb
BLAKE2b-256 215e3d16f4d5ec15f563da2d14db266fca73abd31ee578709089ae7f773f5ae9

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a890de7511499730253ef975df6adf80159beebf3c54be3b448b63b11c283ab
MD5 88f11b3817b38e80bfb187751c428c8b
BLAKE2b-256 e8807b5b05def037f3b501e023e24fe1e4fe710df255c862531bba1a0170561f

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9cddcfeb12240e858065fba45689fe5114ae8a2676b10f98c7d50275d14cd7b
MD5 bd8bb2353797bd722465561ab80be030
BLAKE2b-256 92abd7039b1dbbc7dc20f4c44b6acfbdf65fefd9b04cf404b0dbd02ab72f273b

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b6df1b82450c8c9728ccbe106392dff7be20e4500c9ecdf3d9f29edbb753c532
MD5 1de4854d0e0507af479685e1133da77c
BLAKE2b-256 e299b4297e802882e3afaa8492035c5d24bd104b8bb9d2b793da2ccca901c76f

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc279a2914465b9592c46ace521ab4f4d43536688ad5cd0d72e8650a8de16cf4
MD5 4c60bf6c3e6465b477023b67deeae574
BLAKE2b-256 5095a4988fc6cd49e0aa75bd18902fcdf6854700061d3caecfefd0dba67ebe52

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de8376aeb4caa83a0fd6bf7a00d9997cd378558bfafa417a87f89d2aef1bb600
MD5 1c547cf819db0f08f14d9fa88578a479
BLAKE2b-256 6dd53c58dd0594e8113eb930255b725588a15afdcb54401501ff3ee9bddf8027

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eac120b06a9ddaba5b453df62fdd6714f9eb185538e500fa25075f4625dd9a11
MD5 e8662db695b5d2c664c364cdcf0f647c
BLAKE2b-256 8d3d88102ee6497e07f66ba8a1d70c986e91dcf215d953737274d8c730ba075e

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85cadb8875139cef44793099bbc0d756c507bd05d201cb7cd974613eac4b57c7
MD5 467f557b2bea1fc8d292c0494f99c043
BLAKE2b-256 f4ecf3d78b74f0d48abdf1a2d71f536bd3b796c63df8d3d840e07df759ca03c5

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a42d249ec6039bbc3d0f2657d43182939b7d9bce006e4646d2a3efd791c36279
MD5 8389edbbeb4e678e64bd69f6a4a1daf3
BLAKE2b-256 6e550140f0c4e0e70da7464095328544f7967264906008a82a7d61a15b00e5bb

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