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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0-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.0.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.4.0.tar.gz
Algorithm Hash digest
SHA256 eec6240a7ec138966b29f2c52092c22a47296fa2b25eebb34883104e24efc6ac
MD5 27eedc105f456b41bb1e22752a6301c8
BLAKE2b-256 8dc68b4b56d2b924e3ccd927935151e04710f6587eb011d374f172cde39c03de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16382d7ad710f72ce29e3a3807be47c7f17f7d41589c49e59de62f077b23dba3
MD5 bbdc1d13ba2807a6fcd03331b217d9e8
BLAKE2b-256 bf1a3ccebf535951f7eef041dac3b05135ef9ca08d0ea5f9ce1103451108e1d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c12811e6fe56e72de6a6bf85b7120a98a68e3c65313a9d9fbd808245aa041dd3
MD5 ba9131b29c0576e05b5ace12c532973d
BLAKE2b-256 b50ac7f47097daf8ea1a9e4e9c5147939c976724140668d3eb24881d6cc91d64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3158bd800d22d8ed4ea39dcd873d57dd44782e3e80cb350af0286579b818262b
MD5 1520596e70029aa0224c3f13f97c6060
BLAKE2b-256 3c55245159f81166f6bfffd79145afaf6883f271b895f3f7e334129a4d320887

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6564698fe54585b4e6deb562748476295a9338d9cfd859b95dd09ab131bb250f
MD5 14cee5bb812165a297ed578998ad1aac
BLAKE2b-256 c043dda743e4c94bc7ffb53013bd825d914fce89ce6a23ccef112b3ec5b19ac8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c9ff4f02118896cf7e3406c3168c2a9114834329f5ad8b97270ce8f58abf854
MD5 771d03486d3e695967ef06e3437f3c71
BLAKE2b-256 e052c1c9697da5d3563f3a609ab936b9719b756408465cf198a99a75135666c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa8f066b895399917607607edae57a556f7da8a3a04bd6cbfadcdac645797245
MD5 d76f0503c157fb22e9b6f34045e35ceb
BLAKE2b-256 3713c8c4f4983d3432a003dd9626d14e5685ae9ec420bc42d5759da36833e524

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00fb60693d4031d6479312f0b5c548b5e38483f477d43dc0f0af5db462505940
MD5 b12ef1c5e5634c0a427679b08abda54f
BLAKE2b-256 8e8784d6af93c84b72d850600c564e24e9535600ffe059f58f89927c91b4ec55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dcf31b3f6189bc45537bfb6d7d00e38acba13206ee55e25cf469ce8ec30566e2
MD5 20d269a8d079b307eb98d879d6eed7a2
BLAKE2b-256 73ca59b62f1a21d8f97bbdd8c1a2552e8ee7c9650650ac770a2e7a5fefb8b777

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67ea12299e8433984e9614a2506e0bd23c647988dc300ac6c993f101094e8219
MD5 d304bf52126e1030d7221e0e5c28caa8
BLAKE2b-256 1afc1c4683cc6595383c5333335a38dee25613794c491294c915d1354a5c822d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d33a91018f46f6569b2a27865f60e59e7273e4dc2cc4e8462f67dcb16442d958
MD5 be113513870476d8abde982f0de858a4
BLAKE2b-256 cdacc147a724da879117c390ddeef1a13862b2979d9fbf0926347a5e9a70ce6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f7cea72821cab34303f20781a371ad4aa99d94692e0386185f34f609ad431cc
MD5 676a5967e824c45f06f9906012c73880
BLAKE2b-256 8abdd0b2d60d9f6fab13ef81a44b6cf585713377cfdd3de06f19a93495d2d63b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f32c1950b4732de0b4bc55a322d2627bac8f91670c077a85ad7f5d81bc50dcd
MD5 55ec6c7a9c1904117bbeb8c09e86aa10
BLAKE2b-256 673b50a3eb22f9998b3366e2e788b55b64aed91196f40927f2384975db0f5a1f

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