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.5.0

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.0.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.0-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.0-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.0-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0-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.0-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.5.0.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.0.tar.gz
Algorithm Hash digest
SHA256 510486b8bb428555c6d93546374b746d7abc4734a4b5aa20cdb6a1d18810fe69
MD5 9946dc1d970612df903c1c95e6b453e7
BLAKE2b-256 f2cdb1e47d21336a86661d708e34cac43008574e98fd6817970542409e30edb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5edf31a7bbd4d8b53976550114626199f7612166c37d072a78bbdc1cd20fd018
MD5 9d1f9e88a7a001c4fd7e1bc86bd5b41d
BLAKE2b-256 88127ddfaec9349278496bb69ec02f255beb82484d75962b844912bc98d2ceb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7535868ed348a3fcadc94d6531a0be651c6c582814b862ac31e22222bf7b7e6b
MD5 b7cde9b4c0f2abd255b0429ae1fd3a0a
BLAKE2b-256 b71b415362da21141de60d684d6a693dd503a08bf777e82c94771f9ac9485f06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b5792a5181a44c8be7066fac7af9a45c18ad80de2f0c81a5d14791ae5b2e568
MD5 9ba918aea8160a4d8ed2e35767a9fe38
BLAKE2b-256 0330396ba3a0c902993da0c88453fdf9b52578c2389ee8374a9fa3beb6a4521b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ee5c597dca16ad11f83ed05fbde82de081b11a155376b57cf9ffdee590aab82
MD5 d8f49a50856f1aebb3a6980f814f1311
BLAKE2b-256 e66a5a672c159d41aec584265b29e5032cd3e99f2ebf25422d7fc2b00dbf2cfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c7ef0e662ea5aaef94e55f9eb6d4fad9e8b746d01d7842f8eec9d7b2f2b7b42
MD5 e2567ffc842485dffa4ff2d8d89671ea
BLAKE2b-256 975179ad21b2ce114c7300837ad981eae4781422849747466055cc9db393d2fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0988f28c10705f1d45b9ea97ebbb54afbc37c9c065de1f3f057712d744a8d5cb
MD5 7e468d2ff70abc5f13294dd0f1cb1acc
BLAKE2b-256 67b6db402199d83e381fa5b36fd1646cc9e58c82f0c6f16ee6d6da6b7636db75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 795e7fe2ab8c604454b1eb355052b9ca4976735aba0a847dd25438cdbf100b95
MD5 6f4ee11187cbe117f5d7516bbfe78d99
BLAKE2b-256 dccf79b3324cd6d5fcb08c29f51bca773c78bb6acac30ff4a490efa62a80e2c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0a58a4066b67b2a750652a7bfff5ecf6147dcab4ac84ffb5317ea25f6a9dee8
MD5 87e334885ed7fbeb1f31beb62bab95cd
BLAKE2b-256 6263137a29bf63be51b24200e67d10e87e4ca0f7f6bf5d5f8c3b1fc9cc34b755

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 917b9f2bdf264b7004cf7c2cfed5c67eb6a57cf01d99a095292f909019633bbd
MD5 18bd56dcfd0f7d90b0b94aceed1539bc
BLAKE2b-256 076ce7dcbe7fa15321d56bb2f33f2490fc5c873f2a8e1b2a4e011ffd95f20501

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f43d9ea57f0e3a9685c67e618dcd058df68ed4fa7fe8216cf909fa6209212fbf
MD5 ad1b4a3f3e7ddf4c183d925cc7e2bd2f
BLAKE2b-256 b040eefd6bac8197697109ccbc5024badd9539fb25630a11e6326282db678565

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 143a06ec93efc9e33bc4180ca639a5169f0fc5636497ac486ebe303d9021fe73
MD5 4072e9747b409963c9b2279522ddfefc
BLAKE2b-256 32952200023b7d012f422495277ada826e317089a1afffee1ad595a7d4f3a221

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4b31ab5c70b4b544c5e27a5dcaa9571a304f8888a7228ee86d5315be6b534ca
MD5 4c9172b812d45e41bc87ebd4c7b086f2
BLAKE2b-256 3d9518994445755f2099ff6728cb927440bdc8832c74462eb3e555b9e2b4b803

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