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.0rc4.tar.gz (1.6 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.0rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc4-cp314-cp314-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc4-cp312-cp312-macosx_11_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc4.tar.gz
Algorithm Hash digest
SHA256 0122f837d61612fce83fe031d9ef7b6c69e74c480959d289051b6ab4ed627a5e
MD5 58061decda1e4b3e9a5e8f1d4cc583f3
BLAKE2b-256 8c3fad382822c7485e1f8b17b7caa55885b649b5936d65f84f2e217a1f8862b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5a75db242af63f2b4934b49fde0dffa98366e3869cbf46bfd30c5408a5a8a973
MD5 f89c6359fca72be8fa7c9fefb9541f7d
BLAKE2b-256 a0ce360bf1391fcd6c8fb05f2ad3525285e609a9caaf298c0a5bbc40c0e88fe0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a3dc50287f72166c38698349cf659b6be061e0ab1f509214d6140617031c5632
MD5 47b9d5400efc145a4dc11cc7b56f3e27
BLAKE2b-256 e1d16b8c23df2decdcbfa13fa520071078982ed69099018639ae560572f35bc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31b6789740ade541f444f6345f6b0ad36c2e11b820e9e32af19788ba09284cb6
MD5 de9daaa078c380af66956d61d823e005
BLAKE2b-256 ec8289ed75734c241213e1aac53e009afc9e8f10d9d4ce8081e33cdcd2c7eb1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 634fe05630063dd1bc7c49a47b63c65aa295277a46f7dc3c034ca184742e6cd6
MD5 6a7a1fe8710f5b6a6acf9c9099edc6a6
BLAKE2b-256 9bc3fff7337ba6b5b771ae4f9d012241cb87e9f168828c9a10f98805ae76ec04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4865944904a5975e2c3b0c393c5efe506ae1ee091d5a873f2c74c83a6dfb9841
MD5 47385af172989f0898e714d3c4e1abe3
BLAKE2b-256 e422c88fd35c1308b88fdbc361be33193536ddc883de87c5e240a33f16a90d40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2892756dbbdba3ddb273c2209e9f23e0b8804a65f7d841a65610a88019817504
MD5 3cf06937f3ec9d556d04f6cba23ea092
BLAKE2b-256 a67f7bd6854e52dc338cf2f41e6796c432d900a20542457ec1ff07c5916a78f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f8b5a03266a8be90d2bdd9e4e54cd8afe5e43eedd7a467bcd363e5305672bb4e
MD5 df5510f777f8d0239bea284d6ab9d1c9
BLAKE2b-256 7e6e4cc2580452b07e89198dac03b0154b3970818875b93c49630618ea5a148f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 483b77ad804ea391507c27041faf3735b6796c8820a432980e92b8d3e2dd51b6
MD5 93b98707690205af2fed51b0c420a269
BLAKE2b-256 3f7f9a7d0ab82f1c7cca0acafcb5691af8bed9fefba9368e8298189272a1a3b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b6e79819609de8ad48353d3fb5c1ce58568bdc0b4fd3fc986519ef91c9410e5
MD5 182cd90aea35ad4226734737303cb196
BLAKE2b-256 a26cefe0299a083f0184799479c10e9443997c235233034d65df48db41ffb917

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62704252a4925e9ec67d1a9cf14c81e0749556b0269e67f8f6af57aa3d740d04
MD5 995fb7a6699d93b303557b68c8fed2bc
BLAKE2b-256 75d303f8c2b013de0512eb3ab1e2d07101ae3049157e793f263438bee06f5228

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42aff80f9052b9a34279b9867a0810658a57ebe4dde5e4664fc1e9171e6a3bda
MD5 95771bc98ef08651722f66fd132d9c4f
BLAKE2b-256 cafcb86ac227d0542507b3ccc379df4085ef6e965d080eec5898eaf25387a700

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa05a34ffc64d90bbf4bb6b4e966beefb4b133e362e2de1379101d08fa348c7c
MD5 5d502dbaf93696d5a179f0faced4c6ec
BLAKE2b-256 cd5949896e504e22ac2f5100c7068b46a0087dd20df05a9f847462bf68bed291

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