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.0rc11.tar.gz (1.7 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.0rc11-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp314-cp314-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp313-cp313-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp312-cp312-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp311-cp311-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc11-cp310-cp310-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc11.tar.gz
Algorithm Hash digest
SHA256 3bbc5780fd4efd316140c415802e20e1509774b983359e7eb9545cbd7d4c81fa
MD5 a1de40532dd7dfecf65996221991c90d
BLAKE2b-256 1e5250d0f8aaa1fe273550f704744fd5cbde2c3985d3c205ca933d9679da6c1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4ec078c621ef3a1defa85d92da1b2a07375c41375c3d656eb6038fa85519fcf
MD5 ca68909003f402e9831f72b43c69fb89
BLAKE2b-256 0c768159ec1a7a8dbbc246e4d8ba633026f6c34d74b2552931fb938ec9b2ce99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c60acf1815d0a88016a60e58bef8aa74409db580e544bd3024845a6a48d26ba
MD5 0d034c07c031536ff8992040f11e0afa
BLAKE2b-256 46ce6b081845e474b089caacb2a6d00a017001ce0c8f33c90ddb7252788bd331

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ddde063665edadea624938bae7705b062415464d97d3e55dcea210957993dcbf
MD5 e083efdc9821d6a5f2e5ff8fa8bc43ed
BLAKE2b-256 cab7074ab71f7b57256d2958169aaf4586d9ca1202faf33ab685c557ee1c902a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83c723b4cddac80aa94e695749d35ac657abe2a16d287871486818651c7ba30a
MD5 f859b8fa24de4a716dbaa8cc7f591ae4
BLAKE2b-256 49827fbb192a5a3cb9d86a8bf8c3e2646d97198298552c133282b0250796b32a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ca2728e6dd06338c11468227993ffb4b6e34f133288d54c298383d1dc5edcdb
MD5 252a845972df04e8a6e4e3a7780a6575
BLAKE2b-256 f20c06103429dd0a360066b832c743cfef341a93e846a7f2955c1e1c009a127a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35f3753c2b0066a77157c8045f2081d1d3ae3c11b72670243be52ce2b3ed3da7
MD5 83f73adfd8d90997053018c4f19526ee
BLAKE2b-256 2de8d20fa7db8f86246e1b1c5a51d69635081f9d5f62108ba4a7b691b526c2cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fefcb5a24265d13064e5c0a642102dbe2eb262e414f4d292576e110952255fa
MD5 59d13e99b75ed7a14d8520fb42575ee5
BLAKE2b-256 8b6d3e112a04aa13992ac5d41b87395323b8fb779f420f63ef9494e1d6a19d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 195108913fa2c115ac5d9652a142321cbbac2fb1abbfa89df459f70845b110d1
MD5 09d98c55abf46f9ddecee9f6551c3af8
BLAKE2b-256 29eae60470f5afa69ae6ec9b0cc3124a95978cb089cd4226b1dce87bbe95a3e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d96b77cb1518a97cf4e14ac238f7196024c4960216b9c30d177b3f1ce428ab1
MD5 cbb521a56ac1a3e0976afddef9179da0
BLAKE2b-256 80f5416bb77b4b163b65a00611ce7ba41078552468b5ad75822e03b3b3adc9f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 294c17e101cc37853b1622c5d6528278342a57a1636edf2da0b4cfbd388b5d36
MD5 3839900c27aaac5d1381f9ea016e2bba
BLAKE2b-256 f3e9f4ad75581ed573fc181474214ed2ee88c6ec31e1690fc2f335f2fb4f73d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca739d13c2feaa0f02e7be93d0a2319a62cbca491a8b730f0064f3cddeedfe8f
MD5 ccb09e0c7090be86311b19322005ae41
BLAKE2b-256 bdf37dc0a1b247524a98ec15a026fe5755782afde21f823f89350a2dbb8f6833

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fe5a3dd4d258761f612e8e6ab01ee30320a2744555ce22855ca9ff3196ab30a
MD5 405774302156530845f03aceb12c89c8
BLAKE2b-256 88092274c606f23c78167ea77bca352cc4110620a95f00ac376439ebc70bb5cd

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