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.0rc2.tar.gz (2.0 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.0rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.6.0rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.6.0rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.6.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.6.0rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.6.0rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.6.0rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.6.0rc2.tar.gz
Algorithm Hash digest
SHA256 b86d471c0a3dee9dbc7564b3bcf7082b1df03ea00335850bf7424120304d0d56
MD5 1d8fa27e2bfd82dbf31820e2c34ad167
BLAKE2b-256 c8bc586f580f2b504a6acc833da50d5736b333244fedece0963955e1dc01a4e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b31b6d6e3fe016c8bb3805f845a1a5b224c337ab45b707bd22c869f25213192
MD5 19fcf7e8cd5efb3c8647d059fa8a33f1
BLAKE2b-256 0970f5b6ffeacb7c43bc2f1aaaff2779fb4cbc221505457f15d7e3b4c3531719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e1db5d28286a8b2d115566a625571dc8eb7dd80cc9b28f73b7d08dc58d8bbe7
MD5 643d50c0897cf411fcce591ab529c6de
BLAKE2b-256 c5dd6a9a72e20338636245c1037440b0d635323cc9517b85b0fe84147f6ec8b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe1a1034ee05c38745f646befe24c839e72b0caf4489d386b860c9b89c944ffd
MD5 184bc21ba47e1823d63cd591cc5f1b8e
BLAKE2b-256 580433cbe79037d34080f521901d1a108c953be253dadf372f9bd47ded2ef749

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fa923f365168541a9055cf5a2581b01dc50c523f80e1fa6d164f1af603247e41
MD5 0a6c0f544e9f8cfd40d76d486c76ccc4
BLAKE2b-256 3dec7b0fd7398cc13307e7e54ecbff5a59631321db73587aed957ae962cf4090

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42ce80703ffcf0a632e728aeac34c852371da658b2c1ead3bb3ab859f100f025
MD5 40b89ccf16dadade332596f4b4c735b1
BLAKE2b-256 7324fdfa6f84d15cfedbb34b988f2dd956ebd84ac092ede6c6655cacc5e83895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1784cb99fae7662686c0ed510e6781e8bdd95d7cbdd25f08603406fce7e875da
MD5 838d6187d823bf05ad4124e84e7e2dff
BLAKE2b-256 de9e1e76b5d223dab9a45347a1252b8b96778c54660dfdf1bdba2403a5279d19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a37e0ab5f65bf068f32d2e4f52bfa87c4ff4f9bd9294ce12d992a58a570aaf40
MD5 93d033daa7d7e47625852de444e545d5
BLAKE2b-256 344662d8fd1b189c5be7eab6c8749c65eacd8323f626efec97280f05b6a5d5d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7716e397de2abddb5fc91de34782a2a4f6ca4dbb5175ce0061149b11a2054de4
MD5 85950f8e1b0ab83a1b9ef5009c572f24
BLAKE2b-256 facfb32f1f483df0785527c0d26e62dd14afe2f123c8c5d82a19439fcb29cef5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d08bd445b55718f912ba9c2765399310e7ad50bd67d8f118c73def9210a1d558
MD5 359edd56383fbcaa09763c7bdeca1f74
BLAKE2b-256 4ac9e273f88fe4752398c7249cd0ac1270f8b312b89c93b0dbd5af12122e3bfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c191b70c9e6497c2823a0aaf0132eb8ff46d69441d997ad6037f3f5ec5423588
MD5 99003862da251e599fc2890a59c04d08
BLAKE2b-256 ab58c2d9b51da55b070057faf2cf7fd40fdfb5e06f785a66ca51463a06d60a38

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a875e903695e85d5e39967a547580eef8de5ae9c90cdbe6722bfea00de6e7484
MD5 2a6b02de997a2044a011181898de2183
BLAKE2b-256 c59318c67c6e66946fa3a4be5ca48e0075f7299ac76fb96000a7537b47fbc5e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.6.0rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f49af7ca5f7bf82c4556a12f3432ce0df462b23a2a2f966f6e6a959ce5602e94
MD5 249d25a1d14f22ee9a14b655d5e4a002
BLAKE2b-256 2837feb5a7729d199ad9277882f1a8cef8555cb429e6b04a80a74982fee07ca7

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