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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: pyturso-0.4.0rc13.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.0rc13.tar.gz
Algorithm Hash digest
SHA256 2c591964ef262be1b11718e2aca2536d440981bc7a68a5211ec13ab62e7d74eb
MD5 4dac1415f6895e35e73f32af4e8db268
BLAKE2b-256 b5336b53905ea501caa24303342a30d0e04cc4c986f2a2f042f2c4aef7d73bdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4fd3b5cde1c64d87b15e4667e8e0d266b549ccdb37017c2a829df220545c20f8
MD5 0315967f10b5fcfa934204e27d300238
BLAKE2b-256 41d312009b116319d983d834c9b28536cb5b7f0538c1c7bc466065d792d54cb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a6d989438abf516461465f9dd1586de951d1ffdecb4054500d569d4aff859fcc
MD5 6c41434612d3564bb753797d78787715
BLAKE2b-256 1323f5ce3428e1a447a166924511a32f78b07ef5a6c73a1985b27d2efa635f1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 350e39c0b630d995addbe5b62d6c635fc9e5f319a62bbe84acb5cc1d97fe0433
MD5 b13cc8238868b8f0524a7f31e8a5222f
BLAKE2b-256 152dae650732ed356d1033dde8fc897d2c6880526fb5158b2edd98d56180221f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96891bad1e2b6f4c18187c94dec9acf45d04668093933c2f024c7a724a33b41d
MD5 5c3101a026082d70fdebf446dd207835
BLAKE2b-256 37332ecc93847a8d21dfde33c337f2dde488e2af7a8f63e5e92cbf18ff134e17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c127bf06a4af806775aba5e624cd2a739a99c3090718058e3716eef32fb4e5b6
MD5 81b08677f2c2ba01a1883bcf2303167d
BLAKE2b-256 34b9d621b5343f41ab2c4d525ab7e76e9208436045048a86701e1c00401b1430

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2994c8ab8064b7b5275a5ef3db3fad4664781a7ce7c530c9231f71439dab9a6e
MD5 bd0341b67606dee1b7582bb5c3e0c423
BLAKE2b-256 bd975f4d5311b32378e43e6b2f3c8f5845b3fbe77747378a2e1f89b24a958f85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a544b2c24e1780d7e0a6ae3432f894c82f1117316123a17e184a3103add0b8b1
MD5 a58acfc9df23451884a27d4061e3680a
BLAKE2b-256 2942d5d0cc52d3e1ecf12ee71177f0ddebf0a5ef293c946a1031eb8059ea5a95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8f37feb1d886ffc87968aecbac9ab7313bdb816b46d10aaefeb525a05bb938c
MD5 e9057fd4e47dbaf2daf3c57041e636a9
BLAKE2b-256 7568a22240d5e49f963e710a0c0560ad6b2b9fb1852d61f9b8e7ddcc1c37d52e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c126a18e809667a81d8757aa3a83837f6e8e7d58d2e15273a3249773703f73ac
MD5 4a3f6ccc9cdeb55e146906533142b23e
BLAKE2b-256 2cbd0fbd4fcfa161c35af1ddee642ffa1e9aab5bc089ad27a8e27417246d32ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f331da6d16448cceead56ddff4a0a5578bbd68c6dd31260e6e2ab48804a5b29
MD5 0adc6ea0b2475c882e0a5a242affd864
BLAKE2b-256 cfeb91160f02a90cbcaef9bb582f0966efadd7aab465e32104ffffeadf3da4aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2f67ce0fa48fc450a3c93ff7529b203d71fcd72811d481a2dfcc2a6f37ffe9a5
MD5 a92aedd6cfc6590bf71da01fddefd64d
BLAKE2b-256 4419213b41f001ccd6afad18b8fc25d3d266521b2b87956f7b410e0cf8e1b46b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 56a2473ed5063f18044b1f6391d93598d2c654da70a8223720c95e17b3f14183
MD5 37dd7a02db0621961832462260abcad4
BLAKE2b-256 12ecbc7108626ee19869746ca846ead3797289f814ab6f4a322b4487363f8e8e

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