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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.5rc1-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.5rc1.tar.gz.

File metadata

  • Download URL: pyturso-0.4.5rc1.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.5rc1.tar.gz
Algorithm Hash digest
SHA256 452624faa5feeed7874ba86e08624a4b4edc0f65ddfe033bda43c35141b50c85
MD5 49630a9660c71c542a265fde3ea71813
BLAKE2b-256 5676f3a959fe1cb74ed397a8cd692b62166c5991a0cfd82d1a518bd42dcc1673

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09d3837eb7ce745f287061c9a84707642021426ca3b8515576cbe3e4781d61fe
MD5 910cfd5720c285eafc89ca31971d8efd
BLAKE2b-256 1236985137188ed4680538b8c95f70074f3d2b9d024fd74921ce43ffdb528c8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9a461a0692b6db06edecf2f6d94f7a153cd4376197d735e17f908893bc05c3a
MD5 c616eb85a6fdaf5141d411d38b932044
BLAKE2b-256 00cb207a6a9c47fbe5e6368a4e3f2a3b0685086a50d9cc5fbd2f73ec93dbb164

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70e260503cc92a46c42010c7c47f0dbdf9b4b843680f297b0fd8ecc7c1798be6
MD5 e225a21f7fbcaf383f18d728b5b46f51
BLAKE2b-256 fce2aee57098f80d7ddeee470f57184354bb64f9d9401a6df5a7169e0264e7d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 923458298910f197b71cba37236e972b15a36a655b815d592279c3e1836c38ff
MD5 0b670f4edfca03755a7ba73fc84761e0
BLAKE2b-256 c5c786861d9b11c96809a22567cef101ec589863494eaa07adffb2a0685e4643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d0907c66bbac7c8ace70c7aefc39e0dcde5c434162f95a2858b3dfd2ccfb786
MD5 5dae7b1965e8fc23a89021a79290043f
BLAKE2b-256 cb199afe2b017e99c8909b7e079562dc15c3a9ee5ed9a92afc7b40f0dbf73291

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 735eedea41643dd64b5cc10c653293e5aef700db258ed6ee6ad7c06935f76d47
MD5 e1a04a0719853fdeb4e79b77932b2013
BLAKE2b-256 7388ce25dca3b7588632e2635f299f27a705d919ec14969306b872f8ecbc6ca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 780405bfe1ab5162433ea3cebeb0504ea5cfdafce923cd992a5536c7a956d4f5
MD5 ed803b0ec48345b88f73b6d451d4fe64
BLAKE2b-256 46d908dc8eaaf8c5a437d6dd51b69d94e63937ea795676616bb01edd8f195908

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f307d5486a88216b48cf5d4131ead2638b492eff5ab0c108c013339c92aea2d7
MD5 f530526692e3e94b97adde5dcc901ded
BLAKE2b-256 40b9aa35d61981c4146f903861896cd67ec9db54c8410f7cd3a534f4f8a349c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a53a753e00a2f4257f1f2e32bb71a6b46a145f6b7b7885873837db653e10abbb
MD5 6e736691982ea8255b6bba7b6901efa9
BLAKE2b-256 c49074754f0cbe1f00318b6590a5ab90415e4ca4b710413c9c0d6c12c0de4b53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 442bc8fe7561bef872bb51d1f638198b8ce21fb679ebbcae31d31cf585bfd740
MD5 9e6e4564672db2796d8eb2715fb1c048
BLAKE2b-256 a50db9fecfd5ca6cf6ece10d0b2126b5bf596d6d84e99572ed5fb424da77a65f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 87b3babf693c141661371d899c01d941b9a76cd6490849b9de8b510cdcbf0545
MD5 62a512fd6a4ddfb815c3522345286ae7
BLAKE2b-256 79855cfea86148f1fd8e8b982267ce5baa92e98c841c0d4820a11074225d6727

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.5rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c97924ed7c9d70a9e7ec8c6bd2c87115d1ef62c3d5b354b2ee76dc239603ce61
MD5 f106a6fd637d451b9bcac181853c6158
BLAKE2b-256 0f289a6a65a8ec34582d0b6b7b6cd8d8d997917e8b04b59615d2285e438a9601

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