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",
    partial_boostrap_strategy=turso.sync.PartialSyncPrefixBootstrap(128 * 1024),  # fetch first 128 KiB upfront
)

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.0rc10.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.0rc10-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.4.0rc10.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.0rc10.tar.gz
Algorithm Hash digest
SHA256 2969d60aefb9b3e19bef261a9891bbc291b02ed479c9e37c4ef3c6506d147727
MD5 e0343263ede59d33bdcc14ffccdf2f05
BLAKE2b-256 d2c044080fd1c72a13c814c1ccacaf282612ec45cf62a28d127595dbf8a4e024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aae1f0d29a77c502c5bcb25a73d9e18d93902ce9aa9b0bc118c6d7cffa50d9f1
MD5 894bb2b6f33df8bd724ae9e8a3b8fe4e
BLAKE2b-256 30687643b948f7bb9ac4b14774ab44ac999c2e03a21c20bdd65b0c44d6af7b81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba796b9cbc55460bf6430b3bfae383c4355f806aacfda393f0d2e615534f7450
MD5 5009516c22343a9730572f36a9c25960
BLAKE2b-256 60324edaef0ab7b9364023f048a88313c5ae8b71548a164244e6ccead89265e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98bd5d2ac4bfcd7ab674b80699900bfde9aec70a678fe6283b288a7780d2a504
MD5 b70e0a0cac91cde82a18af7e3236b268
BLAKE2b-256 89385074c99ee578a91654366bc3d97f2ed456f78169faddaeec2d172991c14e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11e56e72e3e86b0bdef6f6d19a1b0e94561024f3c1db1802ecf86a0b20f5d22e
MD5 779f90261be8a980184a8f6323b17df0
BLAKE2b-256 20728726d7829c250e7b5aa45c79805f797c30fdf007d7cae0b78e4798b0d76d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c382484fc73bb799235dc3bdbfd8669204c7a271d803f69ab2c9e04febe3885f
MD5 dbf421e72a1ee408164a8d7717a23075
BLAKE2b-256 7fc0b3083a280e39dd0a9b141694b22a992afce3cb08fe66619bfc031319b34c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 631a0ef2bc91491ace042d89f88629a32be1ed0d7a3117c05b82c7c96a70d7d0
MD5 91dc947b4263250ce40f96c5568549bf
BLAKE2b-256 f6bc8c8e6ac066500e597b75823963454a4fb9706776061ea87cc0dc7f24c19b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c22afcecc3c3f8f474a0f7d3de3b85120f7d0c1b5500cb5b7eb971818cb8b631
MD5 bf1f487553143cfdba10c1b8084363a5
BLAKE2b-256 fe59e943e1587be217b59efe42841c3c368eaaac62d02fa59779fc49726b2490

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 616df612fa71b6e4bdc59c520080215a41f2efd165787d67b9ab4e7d915dec29
MD5 3b67a505084ff58a5d2343814639d7a2
BLAKE2b-256 725cc178deb2cae8e1675efcd907cf46c18af87722aaf75096f2e3bc9bb51e2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7100654581d6079ee57396dbac75f7d580269dc03e9fde0e408ab143587ad941
MD5 9b2881aeb4db821669c9798f64b65de9
BLAKE2b-256 0de055a51498607e42d452537d0c83a790b774286db55c71f2c6faaf451b4510

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 895c2a52d5515b95717224f7ccb883b281cf6b3a1ddbc3b3b0c7921389b64743
MD5 20362f70b84cd259d48cf159f60fc34b
BLAKE2b-256 36f38f150d82dfb551959ec197ef8d99df508ed6f0c39d13263e4cbc28775cde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf7b7b74c9ae68320b9d110ae744f5afa8e0ade1ec7b94517eeb2f57f1aa37e2
MD5 8efd73979da4eed9e635bdaeb65d3569
BLAKE2b-256 3f91edbe05100ecdee6a900d0cb8e5388ead735b483cffc4bf8e7cbed2497cf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 26768ec3442839fb4211028419f76fe6b06f4652a1cd9f0f048af19caba9b70f
MD5 16e2a603d05a4748575a7889121525d4
BLAKE2b-256 235e25c5b188f39bd552f3f41271aca63dec17577e4efaf0a1c0ad69a4b8a929

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