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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.3rc1-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.3rc1-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.3rc1-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.3rc1-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.3rc1-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.3rc1-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.3rc1-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.3rc1-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.3rc1-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.3rc1.tar.gz.

File metadata

  • Download URL: pyturso-0.4.3rc1.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.3rc1.tar.gz
Algorithm Hash digest
SHA256 4c0cf6c74268244bfe3b8bbcaca626528e40f1e6efd9d1b82b6eef587a499137
MD5 323438d41007d36a5be7d333b7fbdd6f
BLAKE2b-256 34c031f87853dcd7179f55eea57b1bca382a7e2562dc66988a66b41a4c40e19c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19dd6cac467699d01e903dcb7449707e4e95cc9f98a613af098755bba074c5c0
MD5 b0363af09933703d1d0c3893659ada02
BLAKE2b-256 aa63eaefbf74aa128d900ae26fdcd2a9a574b14ae575855a694916cbb53fa912

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 881104ed21b3a846757578566c21a86fdce0fc221acfd6587a8db71e37c78fef
MD5 a0dd5c060a5c09cc5332acec5c7f3076
BLAKE2b-256 4d29f399ce283a7f8496ad189f190d9b3d0caf4fc14483167f903b12686ef1a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5b247962d0a31c6a7189089d2076787d853646eb5d4cadcba95a6678e07401bd
MD5 eddbc256e6be607c5a301543e50cd17f
BLAKE2b-256 f249b3b8d2931d7000188b99a8d0d61359b7cab32544e798fb344096c73ae2f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b1f4b776693c81502154ccd18e22446e5a69daa5ea410e12f2d216874581742
MD5 a93b3b4c04dd526a942800caf858b4e3
BLAKE2b-256 d1fd86b3c17068c34453bfe464ee37d8f1ff7674dea07fd02237c683f1af3a12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 691a4919f7296ae4cd06e1bedc44bdb346512649a5b82ab6ea1e45357ee115a1
MD5 ce776fbf4b6a91228d3fca1a0f9eb00b
BLAKE2b-256 1ebb95d7a3cc660c6e84de5ce1a3b73373ead1abb142b3226ee7c96942443a77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a578f55c13255d7c83ea3d1732b7625705ccb348fe5ae4a0aa83a84ac4d6a8c
MD5 342909dc77ce41b06386d67b79f71004
BLAKE2b-256 7a04001b3f9fc60e1bd20b9bb04cdd4d6abb8d616336b14da1a165810796915f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 899899502a02383fb5c1490b901663b9f9342bf8f8c8f89e7ba51fd816537213
MD5 fb72c2669f9be010458e3f5b413fe792
BLAKE2b-256 3495dfd9274f1cfb9f6f464063bb5d8ac206051f27c57183d1a3b230c72786ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a38e90e900e6f52078bf682cb400a5ee5386015bd7a50a9fc918a0cc5ec457c
MD5 926ab3f70203b2afe3cfa82bfcbd2935
BLAKE2b-256 94820419bac59e32f2f21b9229fc5854aed053e774680946e638ef584abf236b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd7b023697965a9f5efa284ba8278b74cf922d53df6a92e68849c76fc3b98b9f
MD5 37683cec04d6b37d9e0110dc72b9283a
BLAKE2b-256 78f22bae1b0d8c9ba39f653bc8509d65c8400135abdf9b1aafc9a55be5c7a097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62de8559c6a5447545399283ec544160aa09bcc5e87b6aca0d027d0edf451d0c
MD5 12b189d2aa37d650c591f03a71977901
BLAKE2b-256 308bbd910d0bf342cf8f429aee3095b5afc59e8171616e5ed6b38c2b87376215

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 739844b94841b79e44897c0605b34311a6056d6ecdc64733c1d85fa05418de05
MD5 60ed4f6039ec93ea40896dc774e1dcea
BLAKE2b-256 a9e970be4637c6d2bff16c2daa216698dd895ee0830f4434d8be38a33708c262

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2cd0c107cc0c48357015e6cc0a8fcea456c861679676c22bd458211f371fba66
MD5 4d52458810d8e0155ef1c0693b8ed7bb
BLAKE2b-256 c6ced46f7a5e025a8831b45ac440030c6084ed49a9ac5da25e8aa80501d3a282

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