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.0rc8.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.0rc8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.4.0rc8.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.0rc8.tar.gz
Algorithm Hash digest
SHA256 4863bd17d7de6224da4aa3368ba0f27de1e33b8adc8dc1367d5161f30b97d85e
MD5 f992d88b03bfe841f0952fb44d22f38b
BLAKE2b-256 2cc29634f0a37c37d41082f178b75334c3e084d9c300c9c7f423dbe272379d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c8ea3779506660b99006b393bf3a5ed753a41cef24fbf1ee842f57bf906fa3f3
MD5 5fc7e7ccef1db6375cd98e6d8e125dc8
BLAKE2b-256 cbb19dad4992d32de1097ad12169191440fca6e694e7119d281748c238a97bc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29b670bcd178e3f7ac0d8bd976277432410e427d391f90bdcd3b3f5e94e2df2a
MD5 fd9c95c257c2d7543d9dd8ef1f8d0d6d
BLAKE2b-256 f28b616b6d1b9e335789a5062165f3e1c2fb96aa6f5aea9be29f25fff159a586

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6f6368b5bb7b18165f2f9b8b331adfa8dd1f95b993c1d216a3c5e233a02b936
MD5 1c923b0278a09cdaee0b35ffe194ef37
BLAKE2b-256 97b936ead843fedf925065640926297ee813f902b8ca3b0a794f15d0612b94a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9625339b3fd74b82ca0e1191216d1ffaea81c660d7f80c70c1ddd6079ab943c
MD5 93f4b1971d852d7b57c6af2127ab1755
BLAKE2b-256 40fcf3d4dfb0389e1b0c151ab9e414eb0d0549dbb76e0bc2acf5ee1da2077cab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b973a8e66241a87741fe8ba3a4aa9c606840e4192b78f41b5a7014005e0fa47e
MD5 57da74caaa7394ee26413b6a7832da58
BLAKE2b-256 cd29926de015fdd2c1d5e3be904ce286f183317c5a79e82918827a2785ab5db7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee52a522d43362a7f4ff58e54fc4bda25d8498edc591c183e1337920b4bc199b
MD5 c2a6abb413f0f7931c8bcecadbbb5f07
BLAKE2b-256 3ab33172efc78a7c0a1dfdcb05ba312a92199d28a33ee8d939a19a74c7da1659

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5038419af85351d5632ead624df1fd2f8a61d5213f7d9ecc8e0af64172952d1
MD5 e1787b48a5b068880b61bd4a14f12b42
BLAKE2b-256 b7c76c28ef4e723381970bb2333164a5133a31cc122bd92bacf0046587152dc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abb211c347648063f0c0edec8965cff8c97a7b007b9b09c92dc80cb8236326a8
MD5 833cb1c101a81fd625cd9880e309d629
BLAKE2b-256 2441bffad0421d43f1f2e8246199e672f7942d0c0d6ecc12014b967f71df1764

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b87776eb56428aaa802d8bac77ec4d446e344b620828cf064752ec59f6fd7606
MD5 d060b5029673d6947b9ca14bef55ddc8
BLAKE2b-256 218a4ccd12ed317d75de5099f2ed25863cc6597fd7ca9fd818e62f347acfd1f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 393105d73d0e8332a3352e74ea9672fc9ed91568cdcbf8fa2f3d803ab4ff754a
MD5 0dcfd8bad4402d0a48abeb9b1d816ace
BLAKE2b-256 e65cfae82ede0c37b5474328d1a5407ada079ea2bc1941ee9613c2bedac16c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c96c8d168cb12ef798a7d6ce4bd3a2a9ddaa5a27b2c4111cf0ee25f123064d8
MD5 d5d03e212f1ac84794a0c5931f6fd7f5
BLAKE2b-256 eca3acf9f5ff35a3156163c17748a7ebe5437915b9e0413b03d763b2726d50ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 225b6511f5d6cd67946cb2086b862cf592ad2b5e74c8c42200488243260f3c5d
MD5 1e52939a87f8f0b751a09493296d631e
BLAKE2b-256 dd6c803f85d69a919d75800817f4b2688cfeff2929920b7436ac0e413b836e0c

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