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.2rc2.tar.gz (1.9 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.2rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.2rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.2rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.2rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.2rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc2-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.2rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.5.2rc2.tar.gz.

File metadata

  • Download URL: pyturso-0.5.2rc2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pyturso-0.5.2rc2.tar.gz
Algorithm Hash digest
SHA256 940a25b534e2f05e3ad3d170b342c0554a0e804119ba4632ca4005aaa61578b4
MD5 ef398a889ea7e8cca326556d7adc03bc
BLAKE2b-256 f342f3f367389dc9edd3caff77a681289f6ff63744d13b66faaff44fcd1c41b9

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e58fe422d02193ae9d59a21458b3a99f1467bc0d9a60f94c4da371db7c0f0046
MD5 1cc94d85194f23538b7aab9998b00c69
BLAKE2b-256 972ede6b2b6036e8f00d1a02da7fbae6e54134cb45d215419908ecc1c595d768

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c412c2a4e4f2adb1602b0bcd0361e863d291038695f416d60963bad0a71ff156
MD5 28a338ca195b364c5d6978cfcdef3e5d
BLAKE2b-256 5f2eba16133c1e49fe993f9355dc4c499372b3cffa92470c6566cc2710312333

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 099171518d330ce976830f84c5406e5dfae8c6d273ca65f20e584c20162c51a0
MD5 8cbe0d07c96cf569c599137c37ce463b
BLAKE2b-256 3b91c4160aa5124f0b8e03c49b1a2a72d6340a655de6d8b5e696900a492aa6cf

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffed7e93f9ca0b32bfb6a7702b044414828ee94bade43deb306f7f2947937cdf
MD5 b5566e79fb4ba6e963dd52cbbf1ed57e
BLAKE2b-256 7bbb5025a163c42f9ff323ea86fbfe924c005271a98ad71cfd8572bb12a350c8

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4166d0bcb3489df6ddc7e97f7c4c374fb554dac3cf31962313f86c241e9bf4f9
MD5 2276eef2e104970d010f09ec51806a43
BLAKE2b-256 78b1f4a2131882e8b6c114fbbdc93ff33cddbd3772257b41de8422e946f3ce6a

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5ee415bb912697e4b0afc92c24356f74c274c29f4a2301798db016aa87634a81
MD5 fd39f8e3deada343e3eb9eaaae1606b5
BLAKE2b-256 ee69f14885ce905fecdcb690704407e167b3a904022849bfb2407e0f2ec118cb

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de0ffa754743266e6b1d259305a4e697f8371bbf2e052ee04c7333d86e67355a
MD5 c7818982c3f9ef9b5fd02956f0ab3378
BLAKE2b-256 e51e14e1ae7e3ac62b356f4ca63bfac0220b0cb71904d93ee823934778abe2e0

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 190e6a006ad1e0fc3e2d4f25059f331dec2fad20e524c9da7417c01d3db84826
MD5 906c1f59b408eed1b9bc879c5889fbdd
BLAKE2b-256 83cb6fe69c28c738c855adcd19e688c591695879d70a5b87bda9d2afab8d9064

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 baa21faaa8ceb0cfd9365e2b118f3182b87713c4cac35d9742c6cbed9b671296
MD5 df489207e65a6f89d400976a0a7549c9
BLAKE2b-256 124af61611f8f7d8a5a0da3d9d07cf5e8d9472d56c5292538dcf105deda09a23

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c33a8d7d466605b1134d5db31104f662b5f3fdacf72eb28cc4908f5ad19df442
MD5 ab706aa7787c3fc9d5846e32a2ee9332
BLAKE2b-256 93c0a6d3c2beea45fd155fcd3c20476eee1f3ca387ec5dc8f01d7e76c24da156

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2df94169d9bf0a02ea2ed4cf3921155de8ad7bd0417c621680187a2d757baf77
MD5 41ef562ac476561e4b49509a4ff6b6dc
BLAKE2b-256 8718862ea80ac3b04e47113b613d3d8dec68758fbb49844749c9b57cb7438d62

See more details on using hashes here.

File details

Details for the file pyturso-0.5.2rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.2rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbec05ba41c79592e779dcd9838ebbecc942b0c81b98804089ddf93e4f3ac88f
MD5 316ca212aca8293a2ee8b7511b4115ac
BLAKE2b-256 21549b5f1cd24c741324ff0b7e01f71a49af9ab7adaae8cf2916073d0b821763

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