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.4rc2.tar.gz (1.5 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.4rc2-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.4rc2-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.4rc2-cp314-cp314-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.4rc2-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.4rc2-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.4rc2-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.4rc2-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.4rc2-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.4rc2-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.4rc2-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.4rc2-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.4rc2-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.4rc2.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.4.4rc2.tar.gz
Algorithm Hash digest
SHA256 b229e3de5c9ae8f32dc0ca050f37f761f1feb948eaaec856675b2fa0995d18f3
MD5 d60cfbf227985a02e747b9c6fe8c860f
BLAKE2b-256 5ba804de896f8ec437ac2bb1e0828d723f4ebb20cbbd1f91634f80fcde30ee3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 04578725da5a43000b8cae31bf3951b9b9a7eab1724fb6ef80f4f9c24288c40d
MD5 cdd6b6ff5eb53e4979a891d87d5412d9
BLAKE2b-256 f26fa7f17e3219ef75381bda35e35596605734a4525010f026eef97e329df702

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d159c7d3e3829fb59c3479363fde2e65b374fb72ebe8ffe07d0f50e057c8f8c9
MD5 df2fa0146765487e8faa7cebf39c2d58
BLAKE2b-256 f58fc95f0528df1e24d148d0a447a81e7eb00d13727b59327b8a52aca12b6d35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c710eb15fdc1eeb8546abbe71d04917aee5738f88a1dc649cf82b073bfa7242
MD5 19be21863d6d04da4ffaa89ea86ecdd4
BLAKE2b-256 0a70a4d9249f48fbd32b44c8dba241cc314f15b148a1dfd90b1d5365280bdb9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 39f24030b7b3b5b1800760a20520f17e98c364b42ad8d2417eae95b1b207c1d0
MD5 7f3a7f45930771487880107fe7eb417d
BLAKE2b-256 8d19baea7836e3c9394c6e13008b1f8c957c02c1cb214cd7a8e2a63db1ae416d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a5a5e6cc98175d1af597ee06a55c9c95ae6238f0fa2436bb847a94862d13221
MD5 78c456ce8f6d6ffa3d501fd263df3ccf
BLAKE2b-256 f9aecffcbce585726f1e12026b8728270198ff74e8a6fce8e072e964f87fb516

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2eec584439edef29ab28a8e26d7053ed0828c9c58893d8089d56581ed05410e
MD5 2db8b5e73f1fa3d4769fdd4cfee900c2
BLAKE2b-256 e857a18d01c66a698c9fba6bcb5e9ca392bbd4586b01086f53c1deddb7bec5fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3093938a4b20b41d528eafd310bb3ec8f42c0e52b43a392342c1b4b818b8002f
MD5 d019abae68f7cf0e5779ff3a1f2bb598
BLAKE2b-256 73bf6784aa35ed9260b8641ab725403114386dfbdf598e77fc1241af041c6c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 183827e5136d522ae8a680929976468bb9298dab4d1d8678cbc4e1c5f11ab6b0
MD5 fecd81026ce46fb5df66b41408ba84a7
BLAKE2b-256 c1ae513a6abc4ac5eb295a604c636755d9925f55ac9bdea7cf4138fd6a4a3975

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7774c61fdab29fe0c66c8ea2170694435542cf13fc99f610f3d0a0538de74f0e
MD5 e1d3694cec327a4ec5f218053a3a18a5
BLAKE2b-256 4f78821047b26303638d729d123877b30c0222999fd9fe39fa6761460c9404bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fed8f47f22aaa0a444ee6bf808a35d05744c7adc51cc80f20c881bb7d6df78e6
MD5 cc9a7fb428016d5b16697b0d3329496e
BLAKE2b-256 1782a185750be66235ea6300b287ac3e682404de4591a1e56086b7887889c4fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3f5f404023d68f4104beee5fd0c73fff3848f76dbb87a3faffb214e9e0560c5
MD5 c528eedde6463b68e3b11ec23382d581
BLAKE2b-256 2aa33e730813b5f09613436dcd310941920353d44b07aff4b7da720cc31b660f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.4rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29bcfe6aa81f4f024daf65b10b2e67feb05f4c21e35191dd14458b40d7fcc0af
MD5 f583fbdf49d54c0e534bb71f4cfe7c57
BLAKE2b-256 599117e03a69b7cf2b98f0241886d0882ca9369be1a01f2ce55468983dbf60a6

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