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.6.0rc4.tar.gz (2.1 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.6.0rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp314-cp314-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.6.0rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp313-cp313-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.6.0rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp312-cp312-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.6.0rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp311-cp311-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.6.0rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc4-cp310-cp310-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.6.0rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.6.0rc4.tar.gz
Algorithm Hash digest
SHA256 3c186a82afeca2062582882e0bdf0449496064d3407bc705e95decedcec07d61
MD5 14065435347813ff9e2d6d9251ecdbcd
BLAKE2b-256 d71db892b391fb88e7a26fd72d50cd13e5013efd6438e5c366c99e51691c4188

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 84f6df00d9c039acd91d0d9d43668e7d295629611f1698eb2e8013f2500cd624
MD5 e0243692f05dd8471a38efd0ef3afc35
BLAKE2b-256 4357ff610ce3590f24536d857c0653260d0b7a23fa0b799b6a94499ff8761771

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7c07fb81325c83347970a4fd8af4aa4db1f9fad1aa30909ddc5cbabef6615ed
MD5 c07dcb1a12e3a3c5e9fecac7ea532b79
BLAKE2b-256 7aad8b2127243954fa7e3d7c627a2db4429153a269c949307d8e68d9c948f972

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f563a123611398caad739a619e0361814229d21fe811ba17d16c3e81bbca5c5a
MD5 ee8118fcd486019b37f05bff0077e042
BLAKE2b-256 46278c95952be2818bb9c0a54f25cd6fb7f7c0eff1fc6f50cf8e5206f5ebb394

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14bf2f2e89da7fdd8f67b21055b9229d8d58fbfa0bcf2c8b39b0e7d71ba2fec6
MD5 4da5f56cb19d3046b9a7a07fdfa1e540
BLAKE2b-256 0fde6a9a88180458fd2c99a5dd6113b1798a2c048e093e00a3e0a94567a11cfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec0a444406fadf8d9634f73ac3191500c67e8e807416547f58bf4382de4d1436
MD5 a66bafe41d7d2e52466449fc651c73e9
BLAKE2b-256 9bc136cc2c785f675c6325ce6270d0122c127ce287042cdaf562c469d69ac665

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40395d1f56e33d7b9df60e61d1e1cbb859850534e483cef8a42683ec13e91e53
MD5 782e4804e657287a4ee796b6fc3b07e9
BLAKE2b-256 b612705caf46fe16ab851066339ac93638337246726830984d72491f65b0b5ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0075bc105b605473499d4c22ed8bc27a75460ed4224ce1a8fb840c9b078972b4
MD5 ec213ae63df9fdb33cd397fd106357a3
BLAKE2b-256 f5aeabe2826b18348f3504abd1a74c14dba8d62c9dc2f6168672eb8b6d2ce87c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7dbc698385da5cdc0715778115be381c02f80dd4fb2d6e3709abc760199a7ab
MD5 f4a55efa1d4e01b7181d878e764f2cc8
BLAKE2b-256 acda37228dac98657286b680d1898bcfacaae344f31a75305ac1d21f3051b6cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b3ffa55d4fbde7efbd8eb43cf6ba2781c3114b702e48f15552505fa24db9b04
MD5 c136819cd8bbbbda8f2981a6a5f72099
BLAKE2b-256 bb5c2470679ce9c5f86c0931eda1b48cf7d69cc91a1b3bf044a9705950c5e736

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a87ff52165da1af50a76f40848a63024eab08f63d9b8d85e4ebed499f967910c
MD5 fdcc42956e1cb8716f209d62a4189697
BLAKE2b-256 3e2416a12ddd8396900d0af9257b6eb237cebbe341476a7d17722df8281af78a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 769d1c7fe1b0a3c179c814485c61d821c4ccaca3d9f9e76a50a5620cece35bc3
MD5 ef2553203a24e2f14622dfd638af1a25
BLAKE2b-256 069e03a28ee3efc855076fa73f53253eabb606920e07ccc5b876bb3ab33ec2cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64bfb045f2f137a13cc45fa1abede222821c9b90e583f94bc105591c93346d42
MD5 806127f818c8ac0f897ef23967b6b8b5
BLAKE2b-256 abe7b60590b87815117dc700273416b2fcf33d7481e35f46e50d64630b91de72

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