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.0rc3.tar.gz (1.6 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.0rc3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc3-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc3.tar.gz
Algorithm Hash digest
SHA256 430cca0c73dd8135ea57f0f27c818756cd310c78f3d28f262759199bf7b9e08b
MD5 33f4b57251c0795b7d6ed4658a7ea077
BLAKE2b-256 49057299da867546c4b68c7dc61d83032a62aa3fcd4f0b3a6bafb11d75c9d399

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60f1ff22e8cf66b348a806abb44a6ea2a768249a66226b880dd539bb9733f37a
MD5 4531d4461d4af7db95ec186e566f0ba5
BLAKE2b-256 5172aa5980d86e6e44db4a7b021898c61d45295917141ffdd1c3a6683543bab5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 820270c8e7c05325a581d8488f4ca1c8c2f7eb26d3e6be3312e67dff0f7b027f
MD5 63974260705d4549b9d1d7e70e54ab26
BLAKE2b-256 0336707b3bb2b4d297f2d2005ad2473ebad49f03347b0816bf8bacdbf2959be7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07c807f54e38aba476dad05847c467c8fa89d25d441c7aa52f956f4c826b081a
MD5 bc19c9b0b9e64343640bacc6b2ee46da
BLAKE2b-256 6e2a1cc7be417cc0442bd101b31ed7f202a4b3283fffdb2e9acde9b7b36ffd3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1cf0e4046ff8ad83bf14c19d70c2b161ffc5811796465b536d22a0e372186c73
MD5 28fefd1c7a08e129c0d4e9cc62ba00e8
BLAKE2b-256 99bcebb9d780a03a861ceea2ebb0a5327b233df0e95fac4a1d7ee0ba15dde8ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 191403af630fba910e8cdbb2aa6a42bd7664ecddf5ac9e963a8bc44867a31d70
MD5 2f33520ee817ffd190055e48b2d22d8f
BLAKE2b-256 fa7a6957b0f0495f5c0286aaecaa95e7c0b330137ef6e2670496c3bdeb2c6c75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c5fd320930dc45a2e8c37448836be9d2ef37063d8b1989b93558bf4f9a7f077a
MD5 1639e790667937f52ccbf85524176751
BLAKE2b-256 44e46afe63c8081c1f3fcb5b18e6cba9ccb8c2a5c31f7bed024031ddf7e3e1d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f2c4ea684f85a1c9b097a8175160e61a2cbdd4d134830925b73b01b2d16a1630
MD5 6c9a33c1babb22ec931ed1e907432813
BLAKE2b-256 991945abdfe9b010b67752d39d2a2a05947a96fae148833bb4ad61692280ba16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 41658f3a465dab8fdbac13eaeacb207ed3f2fa0f150fa838c7ba41fcf5d4d64c
MD5 75fc4f56ce844313017c46a03575d118
BLAKE2b-256 1f9acbc6395bae7ec8576b5b30528e7b5a849d732cc261e04f6f7b7dc1f10fc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60dfb1081a1e8b9e81598a32a74749520b3ba73228e99d9638d00f300672ca1e
MD5 724efd69716d7ed89c90825dc698d52c
BLAKE2b-256 fa65563f1fe0ef0e47dda4a84b563915f0a8428f1414e9d2556f2375b6e9f249

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55dd5c9d996ae8f4f55f43420d0d7d06af3af4ca1c425c1164c69edb64ff81f4
MD5 b8f20687cbd0137548eed6a8b8485b9d
BLAKE2b-256 336da1bbf075299d11cef8db5127afd44e5b7ad3b104c296539f3b55cd9a8854

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28cbf8329760e3a65d9c1ef839bcab753749b2d664f29659c845ed20f0dc8ea0
MD5 0f39507244e42d157491e33c6bc93cd3
BLAKE2b-256 7d9ff2e815f0935ba08ac60a3cc2236d3b6d3870abab2fa687ccc7d1b13e786f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e296fd62a2f921db68febba95b3eabaa1f71f57e6e99726dde6753822d3e0f0b
MD5 9b714b9b92d77bf4f04db25e908b9f59
BLAKE2b-256 c63905b97c35c5949c1c9449703fe166f34b62f83035f8f19f8169dd565a5c91

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