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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.1rc1-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.1rc1-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.1rc1-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.1rc1-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.1rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.1rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.1rc1-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.1rc1.tar.gz.

File metadata

  • Download URL: pyturso-0.5.1rc1.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.1rc1.tar.gz
Algorithm Hash digest
SHA256 b68f7a3b9feb77178d0df4c004c68126d3d3f6ad348ba0eb09983b05ed327fd0
MD5 23538ce597f0053837aa4151e66fbafe
BLAKE2b-256 e97c12bbc41d4aa6b5d4f64d9668b55cfd3e97bdb609925255c66f1947596c46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f08ea4130eefb53f9db164417b11406115ddfced853a71a969303bc1aaf591d
MD5 c78f067fd544274ed21ccac2d848eb79
BLAKE2b-256 1c3298d1ab26c818363bd7ec58cfd733aa4abc7280f17539490b79e5455d51cd

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 273af996997f2a56cb83f5c5692918d57a1207cb1823a8efa7aa327dd8981ade
MD5 2d6b8607cff9db2483007c86deecef5f
BLAKE2b-256 57d532e84d52aeabe305ed7d40fe5b5226955f14ab134b870ed5ee439ce0a8db

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb7f017b2db95cd3879de549c116faf00eda44ed0f8cddedcf0e0383e236ed64
MD5 fca18e319f586a43738a8631630072e4
BLAKE2b-256 0c8fc1b36074246971024f220ce47b0dd12b4c1d1ea8fe08c1138362f7f72fa7

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b69c0fdedc8e2c595db423297809c1981d9738666a65099fff3079d892f95a4
MD5 6a0ba2c993efd16b2c510f79723f408d
BLAKE2b-256 2f7b0327ec944af20de724fce0444e0d0919a06658e6aab1da2c3cf2e5fbe471

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3998888600581eef3ab27a532b1d18badd6b4362bb5a84f3d69ce74fcd71b266
MD5 930b7512d4fb6f3e3f30ae94162f4540
BLAKE2b-256 543d4bdbdfe4d81d69b71794978bd9c4079d5e76efd3b635165fa9b632024b56

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78b064c4560de4ce9b879cb81cea7178777576fc23ae21f78515ce4213be1a26
MD5 ae828f20c68d06d6bc631bd803d436ed
BLAKE2b-256 20ad0eb925c802e18149c0c52ecda333c0b466fa21ac60a6cd5c43c70fb4cb5e

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fb093253456e29331e12c869615afea0e7975a3525dde838c786f959874c7486
MD5 c5497d138110a88dba0afcbad7d7658b
BLAKE2b-256 a54e45c0764cc2be3135828777701b7914e8522b58b76ac73c3d2137d32fa465

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18fa99f03d2208f18dae9011a747067516fa5bbd7b8e69491836fc7d037f0e22
MD5 5bc31dc681c53992f7fd393aa3a6d155
BLAKE2b-256 006d28acaa8f513d11bc22842078799de0c70940764a63ad18ef5a3d7bf9e46d

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e2eed8319c304ec985c1dd8a5dd60cda69d62dd616e737fa036596939d95b7f
MD5 de03304ba47200e288b98371cd6b1fc8
BLAKE2b-256 5f1781f6428e2ec6137de06da72e3e6003641adcfeae25e23aa76cb522ccd46c

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 830d8e33019f720884cef7009ffc921efae1fa6cd1452ac35f1d693322c083bf
MD5 e06ceea1cbe93f32549dcdec81859d73
BLAKE2b-256 87e11d3721971c3578249e21d63ce9cf660d18317218defd9842df71b37c36f9

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1385cd5fe2b66491405a0a7c2c01ae23ed3dbb3252ed81f3386825a0c9cefff0
MD5 7dfe41a8171421a1cf121f390c6f8a02
BLAKE2b-256 f293e1b71e929b16bcfb906730a8e0d2d2efdf4aaf95dc157b410aecaedbbf91

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc6203f93d68a77dd77b15ee961166ef7c6d192cdd610eddf6121297d8e714f9
MD5 6b937ae6fc7ebcd30ae09fbaf108e351
BLAKE2b-256 31871867d51cc6593da209fe6c22357650e13cd0b87c5f44d05365a195259b6e

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