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.4.4rc4.tar.gz (1.5 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.4rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.4rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.4rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.4rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.4rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.4rc4-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.4rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.4.4rc4.tar.gz.

File metadata

  • Download URL: pyturso-0.4.4rc4.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for pyturso-0.4.4rc4.tar.gz
Algorithm Hash digest
SHA256 f968bf4a8ea51de4603798d8979e8ea6b3d4cdc0a3097a8067e77dafe565695e
MD5 f29c1322ad8dc788188e7c4cb6624a14
BLAKE2b-256 6d9e621e77933be94b1b4f10e404e073fdd6e4b51447b7766e405574abd9099e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dac1e142037ba2a5bbc4b353ec7aa97750201cd5880ef1da09d88abe79cf8841
MD5 b09b97aa81d6ff73acc413c5dc597d66
BLAKE2b-256 992310499afdf7c4ee4313e9e169f1c1da0b0f66df8807b347b01b4ed3908b59

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 107d3654035fdee7fe87fc2bf923f135e775457d068bfb3476b0a7b55e873705
MD5 522fdaed0eecb17d6835d79278ecbd86
BLAKE2b-256 965e3dd65c6df983567175071193c5f08d9e2382219f25ec36498c61794a5abd

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c8e6275b020c2e69c7a217df1fabbada2856e3c43229cedc387f0597c916d33
MD5 4cab14ec1442caffad7b3145aeaea97d
BLAKE2b-256 540fb11c727f144233c3dc0ea7871952a114604fbb25ab5126123a1db3e0441c

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f9199c11933bba24e1c22f8abe90560f68ef6e31536e847bdd918ebe0e8875f
MD5 d5477dd040bffa9563572213d7cfd70a
BLAKE2b-256 d9a6898838279cd925c1e30b1ea38ec8aea63d689aa0361a2548e9ee02b17ee5

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4dcd484329de398dd1932774bf2160e71276887231555f888ab3fb1a0b06d84
MD5 0fa49f32f5dbd217b1510002a7740eb9
BLAKE2b-256 cc1871ee369c4ea5437da5be781f1ba9513ffe84eb5230b65a0a7991dcfc8459

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bbde3dceed20c689e97045f32669e207f24a21c5b4c36094f6a7629735fd72b4
MD5 48bf20855ef9fa94b2db7ffb7d322376
BLAKE2b-256 30b7ad838fb55990c2a6b305d0408abe47d2aa0b6ce2e61a25a3c71418c5d27e

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f8c198eb8d0faf0c5346522e3de711d911acb59e6fb18cf60bc2e777c639cdb
MD5 d8eb8c49324fb3d505012376adea9479
BLAKE2b-256 345a8974c12fd1fd127304fef36fb47e67a424c88b8d3a1a18be4187e931d00a

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5045914c352e646af13023077049e32e83e7bec70ee6d26a4452f9c8d05f1879
MD5 ee49ba4b9c06035a2dfc817d29a1dc50
BLAKE2b-256 dae469b3e774e2a3633fd32bd64d372af60ce9d43a1ece3ab502c964226e6d36

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f0dbce756bbf4da6d1cdd81b5fb9898eec4cd2c5110a28dbbc45ef6959f8aaa0
MD5 f2d7cb8718f92d2c2a8629baaf2619c9
BLAKE2b-256 23c62507a29ca2592802089f6864bacf87adc2c7b5c1cae6901c010446bc1b24

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c91237887b53649a9e5754039f29a14b2609d9c90567f374cd7fbf1befe39f65
MD5 6b5af69fc6a3dd4b596e83e24f697e34
BLAKE2b-256 23780e6d2a4f0645ecc2023b36678193e815fde9779b377d110f0961419db500

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f23c0a9e0a60e5a06f8717840de96a2cff179cb6f0558e6df7b00fe73cf8f848
MD5 e5bf54104b012eac6df47fe83e9d0c14
BLAKE2b-256 81d0342343bd19f74a68fc73284c7b02fd7f9d5c55621cff6a0740d49530187f

See more details on using hashes here.

File details

Details for the file pyturso-0.4.4rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.4rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f68edeb48cbae839c6b122f7a7db0e84b8d1d205d25aa829e9ebf695a37cd4b6
MD5 b14698bfa8e624fd5d7b54d7e39f13c7
BLAKE2b-256 c25c0dcc878868d082349a9025ef3fc9d818736d256bed1d2e9dfc7fbe626ffd

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