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.0rc12.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.0rc12-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.0rc12-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.0rc12-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc12-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.0rc12-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc12-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.0rc12-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc12-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.0rc12-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc12-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.0rc12-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc12-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.0rc12.tar.gz.

File metadata

  • Download URL: pyturso-0.4.0rc12.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.0rc12.tar.gz
Algorithm Hash digest
SHA256 96f7618db90cb30cc4fe8851ecb3ce995d24c94155f3df2e1850eada482b3938
MD5 894c88125dfec5eb4252c344c901770d
BLAKE2b-256 0851c68567aaeb4657414cbd43badea07adc3a2220dbef8ef55e2b8802c29ba4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1130f9f8e26520e8bcf7aff2c266ce217f23fb8247d4768bb2615e7ec9f9cecb
MD5 b9c534b9fc8e12400ea4ce3aa0e255f6
BLAKE2b-256 6333b5d68942530b3e4b4f61933cb250af9a330eb6e86694c193ddacb98f6adf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1dc6c3665708b0ca9d3a404d9d5718fb510b6fcb9e60ca4e243e831844f6ed9d
MD5 e4d77f53a0fc86a8c0feea24aff689ec
BLAKE2b-256 d236a7dff33a7015bb6c99b294d7239bfc477a45a778bdab53653c8b42623d0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f4b82ead32a47598ee44f3f308d6034427bc3dd38418c6e284f7c7408c1df6d
MD5 acbf83e2fc9a679bf8bcac1bfc30d31e
BLAKE2b-256 33fc87a1cd53ee7066dfef783e2919f050a043ccb0f9c6d9134783f660654139

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 13c0317dcd0c3f5c9c51514860e000343fe7e02a7f9fc2197d22fbd4361d9428
MD5 374893214c662ea5991c5165d493218c
BLAKE2b-256 f980b2ac687021c3676a5119e4939dd25aa8c4af3882968139342fd308e386af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 461b3730736030c206803314adb78a34480ab7c42652f61e77f6e1867ff51f0b
MD5 931b38bec2b337a157cf9e256619df1f
BLAKE2b-256 95130ad0edf0b1838980f88278d46b3d3572149e1257f644a29997953678e9f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 411db65806fd9dfd6dc8ec8ede16cf18c4c5663231463941da4107a87e68a1ff
MD5 59442de06e8b4789c3b8811cc9313c9f
BLAKE2b-256 9629ad7107e66554dd57d10653cfedfe0ec71f729d8ac66e1934ca67b2436040

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0f44427c8d48f0e97700b5043fdc61b4fb97a49d1a06045d8ac027f8da4efce
MD5 ef8daf93941bd628bf4124f7c7036605
BLAKE2b-256 44bf2b1bb6e66f8ae5f84518780551a98e8a79ed4755ec0ddaa90334eeb09a22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6be45fa7d29568469dc31cea0fb11aec5291d01f4530e891187d032f7d02ca5a
MD5 e9a460d9f2e119ad95bade5bf177f774
BLAKE2b-256 5a22a32af4cfc84f27c27227be0fabc7cbb4eb5ece3fd5e18e85548f2591978c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d793b64ac3b0cb5f91e8d54d9ea1282c8f1e344ab40bb6268eedc82a3d325da
MD5 5af440c4de4b2012df1a70da0454f526
BLAKE2b-256 01a20269fafa8abad4051ebac34d3492055562454d3c34ec0cf8e761a34dc138

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63213cc52f5a1cda8dd92a9936d7b7ac0f71d7a4e34ef6d53fde912410b9a99c
MD5 5344d19d94370acb304be4cf1bfbdcf0
BLAKE2b-256 b46f4811862b4405cca86474bda44a39c2c3edcb14f6d2c88a7393d8ec1eb0a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3003eb5dd2afb45b0b23d729dc72114a0a6db3afd66a73d681061676cc2db718
MD5 b0a145bfa0b90f6fc3c488c61b6f7267
BLAKE2b-256 74a261cccd72dbebe7768a900c108e9fef142835d92fb87df3128d998a188d5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18e40aab0017d64fc33dc91cb870bf8f5d0fae7f3bd5b793f1db78c2ed7b9bab
MD5 658f3a49e70f1e6f059df42c8b483794
BLAKE2b-256 f7875fe63abff9b452c8869d5dc02353d62e92e0567c7c1ab8b4c84c71a183d3

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