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.0rc15.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.0rc15-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc15-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc15.tar.gz
Algorithm Hash digest
SHA256 96d6eba1458d3e77f9b6d0cf10199d8f0f82d9b4d7c3c16fc702cd4166f79540
MD5 130b2a70379c2fd5ac408366c9097f99
BLAKE2b-256 c535cf62207f1d5612eadde23d95e2d33f0235e5f1c421753ef19e36a54e0ca0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 962fed68a85b8e470c1d91cb5467c23c0fe002a906fd905db2cd0d0eb6523e33
MD5 63d6e72c44660698edecc644189ebc2c
BLAKE2b-256 f00415a9c4973ebc98920bac985311a40d031c8869a02b48d5b385fe2d75f63c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78d1601fcb5d2c4903561e984f0e5fc9c6fe40ab7330869aa9e4bd25dcd396ae
MD5 1993f353cacaf6b2c4995a11ed974ea7
BLAKE2b-256 d6f92e358670b68e9f307be3b1b558413235228cdaec56e06129826d519289e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc54553e6131ae2ea6ee725939a96b2c957ba1fbaba33cf6d43e7ae0470370d0
MD5 2e02dee8d2ace6deea31008f11ae5042
BLAKE2b-256 d9089b3d8ae188da291064328ca1f2b7fc259e505ce7cd9da8311b4cad980753

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff0bd328c4e4dadaa81e9a73777cedef65052b68a0da47b33ff05ade0b3a4ecc
MD5 bea22084bd592f2329ed2b6bf47dfe57
BLAKE2b-256 a1dd2054d48364c205ea2832843f07d7a42f07cac4a2f164275e0f144c4ad171

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97f62fda378a1ff84aaa9badbc856e5ae70b314d19881ede33a64fb85e4cfa44
MD5 fb3c2ee7a9bf031efd97d94f9672a873
BLAKE2b-256 c87c5b8ddf25eb0c02a38ca407a0fe176e2446dc89a0895b5f18558773d48cad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 10fbbbfabef927eaca36079d96c507faed5b4f13ab7eaf54abda6d3028f0f8d9
MD5 4c88764d8f1b25a8ffe8bc84f7a0fb0e
BLAKE2b-256 0ae207120239c4ddbf116a625f24b2650e337daf8cf689fae33344ec9662e8e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4df09f1f374fea02de9616b614a17b923d9632b90b0ee9db92ba2f17c1d1c625
MD5 3bcdc1e12068c1c6e093ad4d360276d4
BLAKE2b-256 a2f392b3df6a05edee81ea8998f96b6ed89fb9cf43f2a1065379c5cfa3ed0986

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c21db9933baef7466c518191cb8d3e5a08498775e4247d13c026d8becb50e871
MD5 0b2024f3b0d7e3f22c5d1f3ecae4f210
BLAKE2b-256 cd2b798b52061b8f35de3c7f25b9ccdf41788eeda1b78959df1a597b2e6e650a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85856f937a8753c56667d520763f8f2fcf0fe37822ab5f9e96693eb42e38f01a
MD5 2204d5db282960f8e26c0764dcaaeb33
BLAKE2b-256 8f669e3f2931c30ee88520788dc925f59da43385e1c206046b2d575771aaf8be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5f6956b58b5c56a32860e3cc577bf1bc4102598b8712261b6cde4ee7511ea03d
MD5 9e8d6fafcf01c34808ca8db721e60c45
BLAKE2b-256 01b5cbf8a69c9138d8a59499c4bca3a28d21fd729a7325d472088a90d35667e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be0e9fe5963147525059d45618066da0edfaed6381a252e0d8553bca1af61798
MD5 d166976c79fbe22e38bcc8e463011d8e
BLAKE2b-256 defc6bc41021a715d582e3a83f15fab6bb57f7eb1870ad0b659a663de68bf541

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.0rc15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba20f3715435d09a4ad6c5ea668ba3c64649f8c7f935ded0077ea8534663a94e
MD5 126c5d56e09c87c9c55d577ea7158082
BLAKE2b-256 4604f61bc3b0b5322820adad72e0b5ce4eb325eccfa7a6f7b18a9b739224ea13

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