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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc14-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.4.0rc14.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.0rc14.tar.gz
Algorithm Hash digest
SHA256 fc3256b95d7c204ac2d7b7e03a5a764a6cd7262d2e08401b5eb24c8bc058627e
MD5 4056ba3e944cb00ef58435047dbf89a2
BLAKE2b-256 b9fc753fa9f80d5512ac2d5123319c74cd98c3b5a4e05e22ecfa55ddf1ecd661

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 08c227ea0a7dcdbd538c0528f562a87000a8b03ec295383ca197dae409f96903
MD5 21d530a77b02f66d769fad78a8e4b524
BLAKE2b-256 94fd01247eeb589b6558d6f572c424ef9d0d2beed1be4f78d16ec21c7bbe9272

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0610dd82e5771036c92645a4f22c90c65cec0262e1bb343b2621c360b7c2b328
MD5 cee74cf99b0337bdf319d251083a0ca0
BLAKE2b-256 f8a35091ca7b5a752aa88090a39a82309c4ef6734a69dbf96a025322963f505c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 275a0ec641f69d9e619346d3e11e201d230a9dbf9d359516cad8aed4587247ab
MD5 4a96b901a2fd0bfb5f3156cc288a78e9
BLAKE2b-256 2f513f437223393648a68893964535ec9c871fcbf5f997792e0bf0b0ebfc323d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9abc4d9d002fa8335e65261f02e82368b9bec71286ff4555b9628045f3c23fbc
MD5 84ecc10c458fe7c3ca4c35f19867c560
BLAKE2b-256 7999d4edec799a1cf64c77da6b1a7e408461e11cb710d466d95bd8403f76ea9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18adf7ba4697f0a8d50b8659b236ed5144283ed46dd9002178405785204f4f7e
MD5 14d3f018ad388c650027cb2ada7b34ce
BLAKE2b-256 d58c81ac037455810f02c27960d639ad4a72b6865ce1f64049064e11ead7eff2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c663b4965246c0e759ffa76aff6187740b28720815be16f8f23489ccf17a44d2
MD5 e86d39ff23f868d54743f1969f488c13
BLAKE2b-256 25c3408f2ef6b119ab55939187df7cbcf08b3399225ed5139502aa1ec4e8fb67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a427098b701874792f928c555ebcfceed7877b58de6359f00649f2e39c6377d
MD5 496aea2f469fbd6404d6ae98f8d0d53c
BLAKE2b-256 103f1df76e06c230c857ff21a3031d00ac060db4a6eb165ab6dc32d85c544813

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98cc68771939b322402a1b84d8b2566d176e9d2d1f29201a000525ca7102ad9b
MD5 aebf1eb54814dd1f3d46b60db64da4f2
BLAKE2b-256 868e9f5f88349f82480f7f9d4c8986ad2e01164f2baef7195814923714daf8c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c644a961c242a42c9776b0cb364224234497ec1fd88ef101079f5b864f674753
MD5 f94871f064696220f246f83982ba4158
BLAKE2b-256 ce51413da63f794da2a0f6d490044d4f865a5892a8f4ed13afa9ec56000702a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba7dbcbb58f70fa8e69f80ccace9a756cf99de639a58cff2f41e922eaf76111d
MD5 246058e8f0a39486df0a0b73de1a737b
BLAKE2b-256 efb6b3bfd74cd784fdc40b64e7d411c52a7402574714d3accf04f88146b349aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4dfe0882d047ad8f2a55952b165ca7a2fa523fed30d4c31cd29ee7cc4b80bd17
MD5 134c02bafe78fc2a1ce513b3333818d9
BLAKE2b-256 ff0be6d7e9d2b87b4c9c04c232720ee187cb3704e288c23fcdb338998ab22f41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71e930487f4fd2f2c3b4e3f4f02721c7c80460fff0d831ab930a680613fbdecb
MD5 4e6f2eb431e7dfae3d56299613a39516
BLAKE2b-256 a99a8b4e44cd05ba80f09739e464895fb464e9b9866c2189986c9e3ba105ee0f

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