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.2rc5.tar.gz (2.0 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.2rc5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp314-cp314-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.2rc5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp313-cp313-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.2rc5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp312-cp312-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.2rc5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp311-cp311-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.2rc5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc5-cp310-cp310-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.2rc5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.5.2rc5.tar.gz.

File metadata

  • Download URL: pyturso-0.5.2rc5.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pyturso-0.5.2rc5.tar.gz
Algorithm Hash digest
SHA256 6597c0f27d643b63af90c9349cd500724a8af562ba5698267756354d9ad5d416
MD5 175293959770ccc7ad7c19bd452f107c
BLAKE2b-256 3f41e6d52429f706d5e98fccc4c0f0ccefe168cbf996fc7188533ceab5297369

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebbff3fa98a292461900b1e0b8509c0366ff43e92499b7771539b2ba46365bca
MD5 25d5933946ee1e5aaf74d34731abfb86
BLAKE2b-256 2b24ab9ee0c299d7b268e05ece6b09364c0bf4eee0bc0cf32e043f1b99567665

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9291b4acb4256c5de7d644f3508d5cccaa2ad4b60941255db61b04887ba70bc3
MD5 45e9eedb4d93effb56804500a05a948d
BLAKE2b-256 c2a1ed92703c2bb2c16471f807d6d46aaf693d60b3907e5bf660936967c2255f

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 932fe005ac20b074d0afc92eb828c89b36103a62ff8b77ac22d949180309aa04
MD5 399e95d13bb5489c564388b8d92c95fc
BLAKE2b-256 b3fb384b7979a4a0866970cd2d064612a6b2b2b7eda4f910f37da7daff5faabf

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 178a134c173e60a259ca827811fc3cf967339368102a689abc89ef15a8be052c
MD5 2a3c698ea014b15bc0f5cd841cdf4da2
BLAKE2b-256 536b36791450f102de0bcceca509f66e8c0a77bde9e4015c5abdada58bfe3c0f

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c17b4bd27f3a6808b82d32a36f68f0b9ca0e221b78af2afdf38cd18fe03708e9
MD5 a5c3a17857ca68769c62826f28750f6c
BLAKE2b-256 2334288f7c67013c5795fa11cf8c25bc68a3aaf4229971e29ccbe7e65b122f4e

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be9c70b841e2657092523d631e13b3deb9beaa827e7618c9348dc3f3f0f69c37
MD5 d7e835738c3ab438bab657d4921a2b89
BLAKE2b-256 4890bbbdf20bcb9e3a521af1d17dc85506c212f5ca153538e55f7bce8a5d0061

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dea50598d178405a8a447e5438c1d836bfb39a1f208d74e8c20f5864eaf9e802
MD5 cb7fe52ac45356c076cc9eeb0528f6bd
BLAKE2b-256 5b9c44adad8815c0080d4e57450b6d7a630fdcdfcf99ae23cb69ea9e9db37fef

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bae205bd47251b6efe92ff216ec565d0aadaab55ac5f5d7a174efc79a02d1d79
MD5 a93d12e0e994a3cdb0baef1275576a27
BLAKE2b-256 38c49a9215b2687be073f95fdfbe082cde023090153cb0951e9b3c8c98fdcd04

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 997af68138bf171ee90dacb63c8bbceb29abce670a071c9c55ac87dbbbb564ce
MD5 92a03c41824e18dc1d05110a46804197
BLAKE2b-256 bd5d438194083ffe588f4e0f1ad6c7ff5ea5749311dbb948775d05adae428ea4

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7bf65e7fcda1d9ae180b958088a3c02b5d1273075fedcaff366372ec6a8da0c9
MD5 e1ebf5071f88d8d7001147901a3098c8
BLAKE2b-256 d9997de877c67120ca744acda768aceb66e0a2ec6e5b2f27a5951fe1ceb7ae60

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97a87378dd5676b0c5ff80aa149e863c432661754731090169f8697fe63f34e9
MD5 db960dcda9a4da05a5aba4b9562887fb
BLAKE2b-256 0d06bb989edf874ddc106334aca6f6764cf336eaa159e8b2ffb3d38f7f0d5117

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0133d8a78bc81d4ba79397bba941c047a57fbbe421116f19cafee5e2514bad7
MD5 b0744e777737a1a4b137582e78ac12fd
BLAKE2b-256 b552d26decd968c3ffa20044a82031b1c7a67b98582b7a223ca972723d523b26

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