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.2rc4.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.5.2rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp314-cp314-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.2rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp313-cp313-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.2rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp312-cp312-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.2rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp311-cp311-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.2rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc4-cp310-cp310-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.2rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.5.2rc4.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.5.2rc4.tar.gz
Algorithm Hash digest
SHA256 438b0b1c109843ce3a5ce8907cc7fea813960546919b0ef230def30167aaecee
MD5 01c67ef5a04468974c709df65e0f2718
BLAKE2b-256 0aa7fefa5c27bb4513f38e0320599df05ff8e871c4ebcee0d3ed4a88e5f25975

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6b31e15e8232e571a4b998efd0309641d2393f1665a33dafbb287df22118f24
MD5 9202e9b446c91785b89cac750787ab48
BLAKE2b-256 49bba0aafb79f7a5efcd072e8663b42cd9589eae4323a087652f7305cdaf422a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e8292b76147202a11b48e91df3eeb32bef641839bfbc693f998cc5172c5ce6b
MD5 239d395e36aaf7da1cb90d0bde776a3e
BLAKE2b-256 ac6fac03cde49f29b0ff614e5d97db341fa850a60b9d54d6c62860f8061bce29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4bc07137f786031c474eabc9ec36dc913529f88d947e711e3ffccecd7375b364
MD5 4038b4ad7fffff77da22d0d688007f1c
BLAKE2b-256 1e4b976fb9d467331c230275d14f9d69ca56ce5dc2447ce082d2693e79c40fd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e247716df0f6ee1292e0366c629fd298aa935fb228eb8f0427bcc3809c2125ce
MD5 938e69265efde7ffb35bcc6e29ca5794
BLAKE2b-256 171a24723591f39058c503e162e3f0956d54f98e7cef1b3ce31dbc4c767b677d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cacc5c2f447102806af95e5aea9bc59662dc20f7434816e238e00e0b931fad15
MD5 b0c22b3641fd7e0ced3a9c8022859327
BLAKE2b-256 5741acefb8542159c0aa26be155d8f780471e1488266dd22cbc08f44d5dc46c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cba7b078def9e1647d9ceb36dae23d2007016dae89c4a63dab2f08e618bac379
MD5 05e5276823ec9392cb871f2aa196d653
BLAKE2b-256 634111672a17b169239435e0419e57770bb4a2b39e8c7dbbd491151bcb2cfb63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b76de313bdec44d13b31aad98cc876c86b415c1b282ed21bf1a3609cb8a73d0
MD5 d0a04875be1a75b887f389fe4022ff74
BLAKE2b-256 a57153bab3bd278027c0498d703b082813dc4206f6ebbf55546f3d5f0d489174

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b59b5cc41f75a44f631be2376fe0f0f8948922e628c06c9725977fe0c40acf6
MD5 ee99d1710a0a2c25b237b2cd665a960b
BLAKE2b-256 cb480834c7009f8aad2d5af0c300eff99fd4ac4abc991049efc05f845ac3565f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b66982b36be4e7e22808ad0989a29db522b197aea7818fa4d42d4e35e3700bd3
MD5 28b006fb45e03a67ad431e35c5c4772c
BLAKE2b-256 e4c9a1d8dec8c7211ac9ffafd71504ba4d214a93c17451d739155f6d1454a6f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5e0652d02e04a8f925ad3d94dba02d5e86f91ccaa9b7f7a6779dd03640b2659f
MD5 361c8c89d1dcc3cc622ea0a08ab16993
BLAKE2b-256 368bb9b7e70bb30273ea3fff6c684b45b86981afb46bc6763c6bf9aad65b6c2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7652cbde9be51daa9b6f7382da6893777b020c4f668465c180a68ceada0f42c1
MD5 45452595319f28fdb3da9d00fca0f581
BLAKE2b-256 2500177a0c4f5f079c93ad200fb6fc1f2e18263bb9d11a0d6d35a7831da97f0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3bb70b02ea5ab2bbd5f8f0190c6db934525796d1a3e0a2a64768d5eb3cd3478e
MD5 ad59d7894a1ca315f9147cc2d6e9f2a8
BLAKE2b-256 8b13add455aff5eaf17ed6f90d05559bbfb11f887168e1804a1b3dec65ebdb9d

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