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.2rc1.tar.gz (1.9 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.2rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.2rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.2rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.2rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.2rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.5.2rc1-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.2rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyturso-0.5.2rc1.tar.gz
Algorithm Hash digest
SHA256 fbc5d06ab8866a14d67afa2262287170d7844edb323cad2da1fb2a7e8817eac1
MD5 51c880a4a442f9b393690e0ceeb86bf4
BLAKE2b-256 7535bc44beffbf743489d6e0000bb5038b7b5f7faf5e0035dd35d99ecf99d932

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6fc1c69e6cf55eb14eed562328d7e0a369ce09b41bd77875632317f930d09a1
MD5 a9757b4a3ebbd86a84a4ae531aa40d21
BLAKE2b-256 a87db383d83bfc58fc6262440bb29fed93c831098bb35e33fae8d5c050e943b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3627f9fb073ef30f74a09be0ad00c82e45162e7234742ff1a03fb7bde2b39921
MD5 8cff89575ad1c20da9e9dc3e1f5b196a
BLAKE2b-256 01800dd6b8f693e1445e67f597b0536999b40bfb2b15af4b77435f8ad16b702c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f546a4bc7e7a74c7f53f439ccff2ec5cd82b6e9791bd527722870d2b9e3434fa
MD5 53da1efa0aad2670e8e1859737289098
BLAKE2b-256 457afe25ecf4a035f49fc3a37f47b8a7db8119905ddfa3c9fefdaf5d5dfb479f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0b3421d63c6fb019415587122e0094c91b397123fdef7932bd3d31ed93e4b4f
MD5 dd311d2420f5a5d28a21573fb0c5d043
BLAKE2b-256 529ac89f1fa473fdb57e75928143d5ade6118d54c557f314be9cb6092bd33e1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b829c8fcc508c0e2be64d5550779857bf2fd3170f357f24ba7ab125eb246efb
MD5 c785ae76dffe79313defcece0670776b
BLAKE2b-256 044afa40e2862d0e86e6680fee75a28251c28843a25f3ed4667aa5173494259d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be4d80423cefec67c53943da80e5dd23633ddda4acf44ded8dff2df75f644ae7
MD5 f9bd0a1e015ef4ed028336d72494c6d5
BLAKE2b-256 0f4a8e6e1cea78be0d92a387c2df8e0ec2e41f00a5f2e86fb709f19691f104aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c93763b9099a0b70babbd4a327d668c6d55831d1baa7777101c9e10255d4b6c5
MD5 8f67604b17f8d8cedf5a74a98b0643c2
BLAKE2b-256 37ea96d79f8474a986b35da0b587042d5822817a86fba5609a9ae760e5076776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b989d4db593e2d75c23e102bdb0769048432c7ee06cfcf0486751aa0a2a3f497
MD5 30e95c42a7fb5eeb189e3438915532d8
BLAKE2b-256 568c57fc802ace32b00786c7d991becec4fcd6a9dc4164fa7d2bde4c9035a199

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6592c84f260c1c4dfa0a1f03211ebb41a9726702bd7f0ec6147ef23c43356d04
MD5 4914ce2decfaf24bba3c53bed14cdd2e
BLAKE2b-256 c734d6817712808ec6c141a3903d221b921f4a545f187928f30b6af8dc171108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 415b843f1e9c9d0cb65994c01f5e923e8fcdfc0a74610062d9d96c060ef6641d
MD5 ea102917fb89888ec501e781b1802a99
BLAKE2b-256 df9b1ea9a74d26b45f274922a203d517957eb87501822bdd680edc9de66d371e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dc33a49e1418f2ebe13f727f27d24f37e93f13f06a23f164ae26b3f1e860292
MD5 4ce42525e38f55891d48380973f6a6cc
BLAKE2b-256 968e50f9416efb48d871e1e28e95f37c5dff4a106c68cc1dac72cb8510290741

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.2rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c36f9413ec3edb6476a75a988d09e8926cc07a244e4cfe54eee1b2de15c798c1
MD5 83e2934287a4c1342a8b1b3c1403c190
BLAKE2b-256 1b3288f84bd1da08c12d259858854ffe423599ec1a8fa3151fd25117f86f93b1

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