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

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

Uploaded PyPymanylinux: glibc 2.24+ x86-64

pyturso-0.4.2-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.2-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.2-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.2-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.2-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.2-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.2-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.2-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.2-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.2.tar.gz.

File metadata

  • Download URL: pyturso-0.4.2.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.2.tar.gz
Algorithm Hash digest
SHA256 d1234e254b6f7f5ecf391c412efc13b281453042c5d5002d60ee726b86c90a12
MD5 d1e6d0f5ffcbde1baceac14ae13d8993
BLAKE2b-256 a45e2c6e4d7abf82fd3dbc743245d5b4bc2b5a4915062825e23df09837c8bb8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-pp311-pypy311_pp73-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 12e401c5946f72befce7801b86a344b17733ce08ddae1d0845fab56eabfe2bd2
MD5 41902ebc34ddbde171664eec3fd1f529
BLAKE2b-256 258d8df67388eb8883aafe3cb166a42dd06aa9ce37434f4e038ca7d4a22f2231

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp314-cp314-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 421548e94719f9305586dec7c07a569a1c5816de9faf9156df50bbce0ed4e146
MD5 77cb65c43a82377521846107d0488541
BLAKE2b-256 0cea83201f096b2af77a8e240c95f3cdfb245669b5bf343d872c365065e02a3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da2187d2f8669989050e11cb1e683b3e913b3d41d56b77633fc572df0b66c5ab
MD5 84c505cf7b53b68d8abe38beff54352a
BLAKE2b-256 dc2593867b75b26da0cc79b6e76a73c52ec94063e4d6eda0fe834e3d0004fd8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp313-cp313-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5bef8856371a73cc2cce3647bc08aecff18089e99d402b9faa4f9708d6a1d78f
MD5 cc7f92a99bfea76d9c1f8ecc46063b11
BLAKE2b-256 b3e0f4b66a4990fb9ce0c37ad9f01acf3601f5f59e08d488d017fc00baac0ce5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce6f1a06c7e479ad5b2fbcb248bb4aca7add9b08e449b2f6adbe376c68f02b34
MD5 803fbba5999ca7c9bce0c04de558116d
BLAKE2b-256 f7183bfb6ef03001ab60cdb5300fa5ac4d40f4f0db913c325c23852dbb52dc4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp312-cp312-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 c070a921ae1d3dde660fadb6c4279c5dfb0fca6c7c085cc32baa1b776decb592
MD5 4d9fcfa36705b8b57d29cdf0b430121c
BLAKE2b-256 b97f6230431310d529f90188d1592cb9575e8129d22e543fa8f0767e11a78dd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5ee155121b139cb7b87e17cddd51258cc77105ef76d84601db6fa40ec37d93f4
MD5 3d4d6f09f1f9e02127e3484d59c4ee43
BLAKE2b-256 9b8433939a3004d294cefeefc0e5520432db90c70430e1ec25c10423b70ecd8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp311-cp311-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 7e858b03becd2af0c3382f5bf8a2d694af99980d4638ccb5f32c9e6d8abad095
MD5 f9f01c1044c8c1dbc183d0cd79518fcc
BLAKE2b-256 ef85a27800f84d17d266d523d28ac32f5728f91b206d649fa7c2d331d1bf35bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 749bab6600df7ee950da169a64ffe56f259498aa426c89165bf23d7962081fd3
MD5 e3a73101aaf4b3dc48dcb1b76623b3cc
BLAKE2b-256 de2584e637de213af40846de038fbcee79eec1497d9221c14087b37e1a929d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 52cf59eca649ad8ada8c93ef2ee7e325f1d072a4011892066d25e5c62f768c44
MD5 9f6c70522817f593aa53f2be5aabff18
BLAKE2b-256 d36ab1ae6e8497d3173a47f4792a407350f5b3f88a8379f99819be9f19a13055

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b463ec4ac5a14b48968af8d0081f3f961b24a97594ae4babcb6346ddd4d60c7
MD5 d451cad9fc6c8ce5ccb3b8d9d2929eca
BLAKE2b-256 6f75b1207895968050b59c0217187f6d084f904c7eeb0cd1be4ab0b2aa046684

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.2-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5dd22eb846a43a423d6219868069173b31091c6da54ce0dc7d3735cec4beac9a
MD5 8d6b03d9e732d43d85cfa447a82670ab
BLAKE2b-256 feee68bf406802fb2b719326e9c967a144e007f12d790ecd12eec8d869d80f53

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