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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc10-cp311-cp311-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc10-cp310-cp310-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc10.tar.gz
Algorithm Hash digest
SHA256 43df58f368c04c6170661eca5195142e1b77853769193d260a1b763e18192d35
MD5 382ec09a0db5977882ebf155a255cd42
BLAKE2b-256 72cae3bc114314706824f44ea50d2eb4363b50340805a0231345ada2ca6b524e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0797c5164d9be46bb271744c46ba1978d64b74f7e82421c681d56c4bc9244c4b
MD5 40af924053e7d8dc025b7087e0cba230
BLAKE2b-256 35df41ddb2d993966e6e5777d8ed55445289b1a5e7a33b68aacddd15f8a2e2c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81a62f59b5c94362086b1448ceba133829cefc68bd495d162a623047bd25d0dc
MD5 8c37bbd44875848a65ae976ee927add2
BLAKE2b-256 05c52071b44ab13887fa5fef2a0bd571283368de7e9050fff6a8f137605c9c3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 587266e6a6a282b972faaab457f2d351e0ec803d0c5402e922bb189bdd53e994
MD5 e4e9948d1dd627925d4664c6aa069139
BLAKE2b-256 affa8c47143386a7de53f7bdb0b2b6253ba11b003a4b65b67964eca71e90afd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c914770d40a992b640c09244c2238bc2ffbf338fcc3c1bf4df6253621ef8fcd2
MD5 f87610831272f0c606ffa42dfe756f70
BLAKE2b-256 06336fec249e72262c45da6e46354ec3852ea134b21f986caf720be279683283

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc32424eced94e094d9a62822772b6efe59e0e76861b1615a317a16fbb5385c0
MD5 7eaa6aec0d688fba4435de1bc604025a
BLAKE2b-256 e701fa8a9081a89a464c227c1f75a8bd1fa6406e9801987e8ecd19a5ad3eaca1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 839182be3fbeb7a61ab6687e6ccd8adabd09f476936a9db0c54a1303402d3863
MD5 42885495382aaf7805810673390d93d3
BLAKE2b-256 38606e4f3761c4219d0729378b7370785ab7d2fc141da1b32916d63b1b282757

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 397ab16026a41ba59a176f4883aaa35302a8b98f8adba8c3e06fb34e9b6b68ca
MD5 bab200600faf91e98c1be40d280354c6
BLAKE2b-256 7863b6763a5c0fc4458b3fe66e8aa2380342e19b370adf83233f2f4c142f9218

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99175d5ca7c2b42e22a86bedab34e378421ed27e01f93c17780be924bdcdf84f
MD5 f50543019df6e64ef113c7800c06b48b
BLAKE2b-256 580f49a5733edc80e51d915f46893ddea3f7743efbb2c1914074c83a280ccac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 78ebba975c948785034708ed35d6c9ed734282d3d0ffdc262c3052b6d7fb742c
MD5 d2e83f9a6321b7fb0d4f804e022230d6
BLAKE2b-256 e7fbfb63f7bf685b90f0a784693c1d5f7b160dceb483ce55afce138453343b41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96ae53dedf786baff4b0fb6e52f0d74b95ce4962ca3e5d5ddef016921924d13e
MD5 c72e453ec7107e74004ee4bc8e6b9d8a
BLAKE2b-256 73356f907f2c91c36aa9e1ddef836dd4c5fc254b378fc5814f37c9d0e778bc09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 175e321fa8e08acb9d2a7f02a8a58d998105272f5aee7652192e70b223948879
MD5 c460db7d17c25034d6ac0a1f1470f863
BLAKE2b-256 3c89625263f9d7fa93fd80af85d58757ad1fa2976b51a1cef4adbcd5e9495233

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37a5c415ad901925e1f76142dcc0dbab52f2ce2dbd49b24e020b2763c741d8a3
MD5 7736cb359e1e269558f5138856a6e01c
BLAKE2b-256 fdf8009810a0f71c15d8820011ebc8a385eb5a3d627d06d032943e4885360124

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