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.5.0rc6.tar.gz (1.6 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.5.0rc6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp314-cp314-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp313-cp313-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp312-cp312-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp311-cp311-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc6-cp310-cp310-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.5.0rc6.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc6.tar.gz
Algorithm Hash digest
SHA256 5a7b8afeebc6b87cc981bf6a3583c37c23d5c3d9bacfab4db642ce9700497dec
MD5 5187362b59a3ea7bea52806ae030049e
BLAKE2b-256 39709d8708cfe56ab2d34dbb53ce660dd861b73acb354193032ff5e32b6f41eb

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2358492bcd90aeebff0ebd75d6777829110b5da1db1dfa58f0e512182ce02dac
MD5 18de1a6a7c62f955a5dab0d480711f78
BLAKE2b-256 70deb53736a81f6df09d2cf594e07177ef2c20ac9d89b5d96198228509d2d85d

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d8ce6f3043e604838f52b4869a0c0868fb1a2634c521938ecb09c4f29ddbb2f
MD5 18875b48a19158b500e43f9ab22f361b
BLAKE2b-256 b142175e62f9110a3d6ea8b066aaaa55f95405be1f566c8f285d3425d8df9937

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae515a459924ace11320a4f2587a3ea2b3e105466945093c1ed197f4229f0e30
MD5 84a435eabc8acb2259bdb165296fe199
BLAKE2b-256 b77a6a9e856da53d24217e5c34ab1e081221ec1b7f9150ee97f6284e628d67f8

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 beb3c6c8529be7b7f6ded6ec35262b1fe9789f6c5559a1d854a754ca09e34985
MD5 a70177dbae719d09b9b033dd28bfa493
BLAKE2b-256 7b736e5b46077c53492943beabad838cb36d6b504b31e698aa7ac85be5be1932

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6efd60e9936439dfe51d1a27a56ee912880c5b47813d7ddc2592e5d8460c607b
MD5 f47302b6cd156ae78a89b01a63d8e4bb
BLAKE2b-256 7d11359e4a317a2ae70b2197ce62a8740d3d7cd056fa68d22615426224d14129

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0ddbe199a77c9d987833a5ce41c19481a634a6475794367b08c33fbd60dd684
MD5 cfe7560b424de889728d08c6a724422c
BLAKE2b-256 96365e9219e75d6b91f684dc5f3f50545ef76a502e56c441a6030e69b78e5f5e

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 254cb86242e73133a362bee6b2a4765105e7a68fa93ee6ed639fd97409ab2da1
MD5 96295dbac7f07e43ff9746fa4b0a0bc1
BLAKE2b-256 eccdf2326fb9c8dd586c00e8df4394c64fe0b04f62d7688b7e0886bcf517ecab

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 95e6ca6fb937794cbf471c72bc8f5b141afb66d2bc1d4c89104a40b77cbf2961
MD5 07c250cc8d124f913630d798098553cd
BLAKE2b-256 b9d0b4c08c473539c411d5a55412307c1ca35046c276b7dedf3c444697844334

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91de7e33e83ae6f0f91d802ced8437dd27a58ef93b1f2776258813b59ab868d4
MD5 77d2cc433536b94714c914a6b1bf0942
BLAKE2b-256 a1d1c5bef52a0074ef264c49a0cf87fca509fc3c642503616f878a8dba7fbbb9

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 192a91da15e068eba0d75d41ddb794788dc50a5ddd81f28e2c5ad0a284841def
MD5 4307ec4bacfb68cef42b75fe052a2c8f
BLAKE2b-256 f43fcdda9f8f54b62fa64c66f2e6d961f24eb5d1daa4779a9ca714d3786ac04d

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f85336abd9308eb11387b7b7bf04b0a4b125f33c6467bffdeac515ece0f58f52
MD5 f1adcf370513f635e300f884bd1d89f6
BLAKE2b-256 7cb85d03d7987ed1a6b1d43bfe3b36b603dbcec8806e3ffab64e7b4d03186a7c

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3a87cf18cb4625e8dd1b16fa8646045135ddd1370e945cb5e205fb32b20783f
MD5 cc2feea6c646d660592c9889afde1f46
BLAKE2b-256 2c6742c947d85fad064ad481699ac6ea813cd885fd27440871bebd1969ec71f8

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