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_opts=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.4.0rc18.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.0rc18-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc18-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.4.0rc18.tar.gz.

File metadata

  • Download URL: pyturso-0.4.0rc18.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.0rc18.tar.gz
Algorithm Hash digest
SHA256 d21f9a565292fa1e9ac23d446b4cc26d9aae09267746010c770bb4622d081b3f
MD5 31e3feced37ff14d4e8692d21a5f4ad6
BLAKE2b-256 b85843aedace442ca00646cc66f25fe7dd8cecbfe831eb1d53530d5480720f9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 668172df29eda388cd9d02138381eb60cef5accfec5ea16745e4fda68fe2dea6
MD5 06a2574234d235384b6ca02e46a0320e
BLAKE2b-256 b9fc3f0a2501e01d1acf459a60e8257e798c6afcf81809aa30b4491d6705835c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba376df2b26b87671188f57ce46141b9b5a419e0b2fb8955bbd00b9514147219
MD5 720977fb236faf4cc04f559ed24db514
BLAKE2b-256 cd91ee29388ecfc1949108cb2c660df41584234bd7f23c198e38e988c82f929d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8780b64c0f8873ab3644eeab44fffff733f25b11f49cad84ce5f7e55ba0cea36
MD5 24728cf333586eca144b7d7ad2cc44e9
BLAKE2b-256 1e11734b9e1aa40dd67b45686a22087929f707a8df7f4b6a49a1f806795ee363

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3765e1e9690a7a7cfe5a005f4eaf7c11bea47c1cc4b5a24dcf3afa4e857f34d3
MD5 e08d2c6043f1577174d12ee6bc1978f1
BLAKE2b-256 d7587e7429408a305ad9d7f193b5cb5ebc55351631e890f08eeccec77511d6d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0660d46576e0a656e641ee3263df43c2a142a3ec49913ccbd6dc98d55c32dc37
MD5 55982500a203bd00de511abb83849e1a
BLAKE2b-256 163ec2dfd165dedd0e008a1f1023774e8b1694ca8b47e1ffea848d97fc9f5dec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af6e60a60b0d06f0230a4b7b83b56be30f2758733a4eba6b64272566b1d77eee
MD5 f5d5f77a5db2cd1081871bfba11bbf47
BLAKE2b-256 2c2891de44e73ae6508cf3f02660b45c8da6fed18aecaf049e03776e0bd33349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 952a27a0368fae777d0669e8228fd6dce427274c5896e79565f27d0455b3aca0
MD5 108332c22a202da45efc2855caa3776a
BLAKE2b-256 0e5b201f2cfd6be1038431c2f167a97403c5e43fbd626c19b6e4b8da6d5e051d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d33a7b351d7990dcbdd419d8c2a322ae88466387d0276a8e438ea601ac870f77
MD5 7af82efd6567848935636953adc1f342
BLAKE2b-256 7d35e0670ea90c365622e9e9444d090ee7d83f0ba05af1ec5fe0da2d1d18d637

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 96fd73a859d75499a586e439d2c50d6507a9969a73b260ad03244fa1b4184318
MD5 9225dc19fdf554116c318e716835994f
BLAKE2b-256 d457ed02471fe835f534db8d77b545a78125578507ed902762860840a094e0ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29f4e8a50fc579fcbb7bd3b79ea7880c12b6e749ba97a35536aec89005866e8e
MD5 67a150f401b32fd872bef6fb7e8dd980
BLAKE2b-256 c26619257563b4befea735e43857bc76d4f0c7feb00272a08a6ed8bb8cc29a77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c16a16a71a34eef593a507cc04db5604e5b9737afa42449cbd91c6d32cf1272
MD5 9bda0d0baf8cecbd3a96d4ea99d16eec
BLAKE2b-256 a23917d0e4c56746f0f7bf20e85ee16a5466f8f0636999044fb2ae5c4359511a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 741beb83ad1d98ee435074b1ac5e08eef4514bb0c0a4764808e3690b5348d754
MD5 b4ed4ba61e1d0e4a2f13f477be93af65
BLAKE2b-256 879a8c540cc439b6b7c660567c114a975d8ff16a59dc8339cd1b91ccdf63b673

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