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.1.tar.gz (1.9 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.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.5.1.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.5.1.tar.gz
Algorithm Hash digest
SHA256 418c186393cbb4fad30baaa4d6be18fe03369cf4691a4f42fb459758c92cb5fe
MD5 d77e7b193da20f90970a6f83665f1ccf
BLAKE2b-256 41890b25d31d9b4babd68b9f3b2010eab553769fed81df0fad28d6646a13f147

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90864f4ba0cef60695bd61170a92e71085ac6a4f538428a37b2f87821720ead4
MD5 24f8261bd33b10d3ce25fec3c6de0961
BLAKE2b-256 8f759c831f0200fa6c33791510ef534747dd5414c2933132526d02182735c8d2

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef8822aca1a10fb60d5c161669e55e1347730d99a8943cc7db2fd1028900805a
MD5 3dd3bc839ebb5c4ad0dcbbf9cb502460
BLAKE2b-256 58cbaa78241f51e11d3bda76b8e2551ef18226b2c8f5fc359766a4856c832298

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2e10b4d4b47a2db2cf47c4cbf0345bbc5a99b7ec5528101d2fca5fd03f11e878
MD5 31c0fae377e40b388907d878e62ae6f0
BLAKE2b-256 55c25f61ace6ebec4d023983ea797e032820797ed27ad565b824f40213a19c6b

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 baa8846a322434a8b31c2acdd20ed19bab2de770a5f295b9892e06c1b3fb84ff
MD5 763aba017f287f9fbfd8ecc8bac96523
BLAKE2b-256 fa5baaf24492637f246adfd79d3b62d7de4440240b741a430cc0b9e9b551510b

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 030fd5b1bfe72f82f125e4de31f2298198d460a7e59b8602fc0b51af504fafe9
MD5 0ad8d0f320eeb894e14759f0c65a2eed
BLAKE2b-256 d4762a9c43f08ed81f93fcdee85d0312b34f8063310f6a79e634cd4639765825

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fb8d30fc5e009cbf213b368fd8cbf6adf11a5414d72bbc6dbabc84163cea15a0
MD5 8a598d5aa55aabbc03e3d787eb644bd7
BLAKE2b-256 0f7cb61050ac88d2436b3c0a0ef72b0a0b25a90f127ad62231ed48ca1feab5b2

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 421e20af94af79023974392bc197f5cb2a0f9e64b508b7f37c6a5bd323801505
MD5 e25000028f68901ce553d5298a0e0e9d
BLAKE2b-256 c11968ffee644f79d6764c41ffaf14917a18174b285e2a5dc17122aae648e151

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 694a1fb671a70ea125f3716bc92f44f6848b0e89a74463653b24cdc357c6a5b0
MD5 5d51a431b098640276ff7ffc7c0db4df
BLAKE2b-256 d70fdfde41e0cefbf5cce1d498e945d5297f266f674ce9752b849fbc9be80b23

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0846623e91a47d38052c180c84696b6915acb194f06531d4b214669ef843e422
MD5 1a993196d9e9f126663210c50a0108c1
BLAKE2b-256 946f2ba05f0d5d87bedcb035dba1b9623f9caadee6aa7c0f5c1695dfe3ace4dc

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97917509ae687536355995bf3bbb451e5df792dd2e402fffdd5579afc039980d
MD5 399466fd1e3da7f9bdf59267c9bff704
BLAKE2b-256 5d967aef9100fe3d4ef2035fe411a67dbd27fca76062a5bc7bb35eadbc20d281

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 30c900a3e007356f79dd31fe7246cbdc5fe412ec7b01987e04e252a07af05c2f
MD5 df534cc43351e679349f805c6d30b7ed
BLAKE2b-256 696c5b4e0fe94f9ed7da648596db2a4062d429e97fabf46a22928d85ee706944

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09fedad2cf040fa3262bb7c80c4fb0803b4d538524d9de5ab4dd28c7c21f4976
MD5 444f0b7eae65acfb9838d746e75d8920
BLAKE2b-256 2126bc2017f6e1067ac459c967649f2ad18bc4ebde0ae276d0ccd22b24d84111

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