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.0rc11.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.0rc11-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.0rc11-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.0rc11-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc11-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.0rc11-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc11-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.0rc11-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc11-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.0rc11-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc11-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.0rc11-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc11-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.0rc11.tar.gz.

File metadata

  • Download URL: pyturso-0.4.0rc11.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.0rc11.tar.gz
Algorithm Hash digest
SHA256 0376e74a8ff83c7a823fe7169371cc220a1c526b07b58364c44555e44d2064b6
MD5 b9100fbe70c9212926d304e46ba1a8ca
BLAKE2b-256 b003933531edc7b3cb313d3b019cf6079c622ec3575df5b01f8727c813016ef2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2efe4742e00dda7990661d95e8526adf54890f0d81e461d974efc19a69bfb7d3
MD5 57c3b4e273d74b6b96eab4800df0a651
BLAKE2b-256 d2b5fd4676d4e8867556a5d5dbde3abaa65c8fc4b6a2b4b74b90b3d850df79b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d16076c71b63c8dbb0c56a2348d67b4be762dbfc01f8ef5997c838844fcf01c5
MD5 506217334ec65556e724069333bcf2dc
BLAKE2b-256 c609e827c37fe3a84001e53710cee84eee1795521ace9f82531a9f47f61f67a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 733a9004f7f116697aace8a4255817b536e9adb3bfeff5f90baf761ea0ba6c47
MD5 77b257ff4f9c20a7b0e27b9143382684
BLAKE2b-256 5239e19e7ceb4b4a1ad3f5c235f45442940d03cc7531d7c5227c21c12dd21e9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3537544ba92000860f500c240e31fa1f9993d3abcd3ce2aef181a888af095df
MD5 87121129f96c3aaff782be30e4f321c9
BLAKE2b-256 f52e871ee669564cad94365bbea74cd7dc254288e836c0df982084857a6fcb56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42540b174cc309619367bb41e450c61d4132755e724ae51856aa001978b26635
MD5 c2232e1d1fb6c55452d2e816f4011d65
BLAKE2b-256 b6924ef52bbd54dc74aba6286a70a7280c83eae10e935cd64db31a9c2e0c1a31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a0a199883ea3dd18e91b6270b87d32f8828a3a734b382f972748d56b96441b1
MD5 73c4458e43a6c2900fb658034f2c9471
BLAKE2b-256 1f0e53832dc8a94a32e3d9f3d298baaa628968e107d1edca69425fa35ea87697

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1bae1421c55c48e88559b2c5a14726dc97f3b777e630a30776b7bd0f12790457
MD5 348afb75109c6424ce56e4307a8c586f
BLAKE2b-256 40acd1c2d36451d78d5b6f64f3ab66fae9ac2166cffdb6e5224597f620275495

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b01f05f3159be052383110bc405f59f8734b1df095e8618ae0df937fece7c756
MD5 6d5c2c8e6c60c5dd3fbb5b39df4b7a1b
BLAKE2b-256 07b22d3d250989697a5c5c01890a57d20d2fe3c043fbe08ad94d859685f2b929

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecaf2ddc84ee5426f91e78181835e892cc5f6f722f52eb02e6e9e912ff0daafa
MD5 60864d98d6d95a7ef211ebd5261c7e0f
BLAKE2b-256 a570c3d995c17aefd2146cea8e940648ebc2f73249961154f14d3fdd41ae9080

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c3a5e64a8ae5c8716f866d1214f6245eff03075f98ae2fa35d8e67a17b3829ec
MD5 79db990dc45e2b5958d84ec8062810d8
BLAKE2b-256 7745a50c32819eb506a62e480796a331429fb555d139b8a3c8275c40adaead74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f2656fa921133aa2287092bca7247e0d082e1f5532135412b3301c86931a16ab
MD5 d0b432394225eb95cc45db3827e103d9
BLAKE2b-256 c0dec36a3b73a7a746e5e8d959c44e3ab9d5b33ede4d9dc302bc54dc38c1517b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8ecbb36bb287538063cd7e18aa1bf787c69af2b6f77f11a165c639f78b9e0e5f
MD5 130af3f3561e11085253981f77efc818
BLAKE2b-256 ef722319fe1332469eec5171772bfaef02982b78a6636c2fcb2f6a8d39f665d9

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