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.4.3rc2.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.3rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.3rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.3rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.3rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.3rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.3rc2-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.3rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.4.3rc2.tar.gz
Algorithm Hash digest
SHA256 9e393faa7b2ad9ce1c554fb9336e7391d8dc3abb3e62529929e1465deb287be9
MD5 adb13e314fe8ce03ef2992012ba5f9db
BLAKE2b-256 0db9d016cf6d1d26d6c74b11a6ed7dc8fde15c875fae4043752e05599fb41b45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8314259d1553ddc5b7678b5bd737284237e8cfe812e20f1a85a8fa332d56b3e6
MD5 cb0c6762e8a33159ccf5820601193e36
BLAKE2b-256 1d8e1d074db411b9bf3575ba4918c653b57af71aa5e457de0c84d38131b01add

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be286dcaf5d952ab6c96c105a6dc951fa0c9d2df4e669d118f09a7b8baeedc54
MD5 19f9221064b413493a09670f627ba560
BLAKE2b-256 7bbc0175dab0983ff1b7ee1dda44d4c47c872d55076388b951e6a2f2949d14c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c546057a6eeb5a9561013779a3615df2961e0c944d95dabd903aecdc0c11a0c
MD5 8469d7d04c017eca70ed314d3f4f5b29
BLAKE2b-256 978192b96cc6e8fab427b16f5997e969732678434e894770320caa545db2f593

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1fd77f5e4030748e01f3d7d481b4c4a3358e53b88db80b5dc502780bcdf2c5a
MD5 503498c09ac953619df24e119f8ff1c5
BLAKE2b-256 de0a3e5c69198e9e2f0458c4559d2826d70954bac2161577e09531d1935e9d4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4627bd3cf49c5cc82520b2aa627bfcfc6f56346ba1899c6700d20d3e05d2c485
MD5 aaa8109b29800c0ab16d8d67dd7453a7
BLAKE2b-256 5da94a663ac7ca6e73c68af6e68de5c5d3c4eb049637a4e867bc042418fcc991

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f436e10c7b0e6eed7fd823e6dc2927a8f8386fc2fcaae55aa4eb7a644750947
MD5 3f1f038d86e7d4d493838497d7d8c834
BLAKE2b-256 7ae8ef6c66e95211bbe79fa3356fd70ddc7c66fde6726e7f7eda4789563e9d76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c47e85c16290511ebce1d02161120e101c1bd39702e80fe2972e52e8a905aaa
MD5 1f1d6d7ba75b7c039fd7b586a765b5a0
BLAKE2b-256 f3c18b3a1571c711b32ae1c41aefde40767ff8f61582adf51576e8f63db55173

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f74916e887a1008d16e55092d43b235de2de5ad98cc9d5b5e4a4f5c0957630f4
MD5 4da4cdbc6e13dfbd35b4bd0073b5917a
BLAKE2b-256 442732e8326c65f45089ab93469ca1d2a0733bf28a332710b633cecb16d419a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a22b8aca2bc7b0c9184c683a2dd6c6eb86baf598c49d3cea8153a8bbce6b498
MD5 9086a3545fe32a35343f022cb2712d45
BLAKE2b-256 f143f1fa3178742dc2e7d174478d87c5d4f8b187f8ab5af693d5c61027af148e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96b60617368e890b18931ee9cf5856675aff1a18798bcaa764e9528b14db9a39
MD5 de63cd02158f394db631e8f53ade66a5
BLAKE2b-256 2ba170962f312819f39bd77c33b6325d0ac44a77ade0884f79f1a1cb5c25a761

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a31f08ead078ae0e97173cd203d93b808756d86592bea5098cd467e019d0c454
MD5 93fd899cbd356dfd9c64d7efc67fecbd
BLAKE2b-256 53577b36b1709d55f15d7aeef53cbcc002ce0135fb0156e7286551ab72204b5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e714ac737915b56a1d0dc77545910107fde83df37b8f0ae0762580f8c506e6a
MD5 ef4d655613fe84e2d929b07b1ec69358
BLAKE2b-256 bee17d267ddd4fff4736a210a885a4039a6fc480b8ee432605b6c62e4fd1c87c

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