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

This version

0.4.1

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.1.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.1-pp311-pypy311_pp73-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded PyPymanylinux: glibc 2.24+ x86-64

pyturso-0.4.1-cp314-cp314-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.1-cp313-cp313-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.1-cp312-cp312-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.1-cp311-cp311-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.1-cp310-cp310-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.1-cp39-cp39-manylinux_2_24_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.4.1.tar.gz
Algorithm Hash digest
SHA256 cc2d72ccd0ba5282672b9f9f632f0ebdfc44a2eeb725b28ae738859f67ca6cde
MD5 c914262b5a06e16bf2c8d2bc2980f69f
BLAKE2b-256 442fe175642f3229b2dfa59ed6439e6b5e05ebcebd0e2c0713eb2c2f149a9a25

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-pp311-pypy311_pp73-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-pp311-pypy311_pp73-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 669c1082e49e52e852ecaead8645d9d27142a0a48e0409e6eca323ad0b8acecf
MD5 6594213ecbcc04278c4d554a82fc4a81
BLAKE2b-256 dcd83c420da6b245a1d5bd02c935fb79f25cf191043924d9576341b907272d8c

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp314-cp314-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp314-cp314-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 132dd7cce0c45a6ba2f4acdaa10a211dd78690ca0c07fc921cd873cc5552ca22
MD5 557a2679497ff868b1e2031c60f31979
BLAKE2b-256 fe5c19af089fcca05e9d7b683781b75a5f2f70ec525d9fdcbc9d981b8b3cf8ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf0e2b0def7ea3e5a32bef518ef315b23c9f1ae8f5dcb485805014c779a3d6e4
MD5 723d8d39d1a80399c4c28e92e8604335
BLAKE2b-256 9892e43f38584db22bda9f43d02b1f71a5650b7cd5d1d87b4fc1bec40923a488

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp313-cp313-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 3af65fd3d89aa6d3dd84320565065d026f90719569c297adbf63be29401ad16d
MD5 cc9b7d61dbd9319c4a6ab866e2a566ec
BLAKE2b-256 64bee31529b200c872a4d3342cbf9d093d3a95c4ad588361e2099cbd5f5be0c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6c268c88017f1a8b146f4051d226678dab7989afbb3b677ab43995d45105a03
MD5 b8ccf8eae1f46bb58dbfead9bc3dbe93
BLAKE2b-256 552843904f680844242bbb18dae9a8667bd5ece1db5012fe598e5c7a12e9d54e

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp312-cp312-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 10c6e0d5eb7c73f250fe180c56b888e89c70d4acb89fd2585a8ab51429de714e
MD5 f6fbca977a6f651ca47663d33f83d3b2
BLAKE2b-256 fbde63527e3df0c93e627b4544b12efb192b28dfd9ae820d8d40cd2ae0ea7f32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad2a464404deb609a37959330202ba454464719b0a91462c3e614ab6c3b2de03
MD5 532630ea40f1521d72a907a74a4968bf
BLAKE2b-256 b84dbd64660b71d3e2c30f8b02d06f7462946b22b301af5108ef6483fec9fd93

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp311-cp311-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 d1a241704b33a71d3f21f9e5f8f449b0138cbbb682facc9c547dc8d56a1e9a6a
MD5 c1b3f57c640c3c991ce914f6383d04f9
BLAKE2b-256 77a04f8729013e39fccaa06380540dde464ef840a5ee8f774595d34a3a1add6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07a4d09b7bc244ea8e94a4c1612ece18d8f03bbceac189e6cf41ebc599596bb6
MD5 01f79eaceb25da415c864e4b89b8531a
BLAKE2b-256 1a5ff13284e7552ef042a44a60747fe6f9e994bdca6fffae1fa5dcf96c11eda6

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 87a9ea6c2ec72ea2abb6d2ea7b2845f024a835294030bd026a40528cdec52ab7
MD5 3dc86f9876ab4decf95d693ec2276f07
BLAKE2b-256 8932f15738d37c69f4dd8904b35f0aec7ce02431a53d3b0c1ec9c599844a7c13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf4308a06f10fb10cf8583910fb91ff8a345c08e1f90bcc18b6cba27597beb67
MD5 74b14710ebc4c517250ba6c1c82954b1
BLAKE2b-256 3348091f89b7c09c87867abba072b6da2e8446bb102a6e6ed09b71ee048a70ea

See more details on using hashes here.

File details

Details for the file pyturso-0.4.1-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.1-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 69660ec47e16c21064d9ff285bf5abfecce712f79cbfe49f285a9068e9679d92
MD5 ac9433809309fc3de19213b7a4c7a089
BLAKE2b-256 fd7383a5069eb10e05a066272a8282e6f6accd365877beddfe735f29d46cf4f3

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