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",
    partial_boostrap_strategy=turso.sync.PartialSyncPrefixBootstrap(128 * 1024),  # fetch first 128 KiB upfront
)

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.0rc9.tar.gz (1.4 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.0rc9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc9-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file pyturso-0.4.0rc9.tar.gz.

File metadata

  • Download URL: pyturso-0.4.0rc9.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for pyturso-0.4.0rc9.tar.gz
Algorithm Hash digest
SHA256 bfbce9f59f28920e427fa2b06c697fba9c4345d3e980c28c6fc99659bc04c512
MD5 4a970189a62c8945f01e330a6fc68545
BLAKE2b-256 333bffca1100a19de15cf78b8d5ecd6c91db98dcf416e78ab1a17a010fde6aa9

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ae599a532b9e78820ef88bbf417dc8fc50b451cb5862a1a42e6ab9b67db7271
MD5 9ae90b7ee9662de90d383a4605a2c7f3
BLAKE2b-256 8f47c3a2477428fd6af8026c490a23be566eccc8f12862592647e62a4ed04c95

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4e4285e8ac1b10e538c0060e32e399c281991da9de5d1c39f940560ff46c332a
MD5 b57a0629b5234c82a804f0e6f6077df7
BLAKE2b-256 33fa5d28ab4818ea9f70a6eea57e4658840974669bd781ad9633c56afc90bc88

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9c66c39a3acd1c13a78de8b87e3515d9b64edcd3437aebca70959c81e941c30
MD5 d960fea825879938f703a5ee988836d3
BLAKE2b-256 590e85dc28063402873b6f47d6f1d8632da8203f3402bae66ff564bf6fd1b56a

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71ec9dea5f6694b0952a1a04fc7b63e5d2e369502b052a00a3e3901810b46fc8
MD5 a5532d4d63f7fd516c70f16784782277
BLAKE2b-256 e61e46cf27876263d6bf5247773004e0f2e0ef07a34a4b96fb52c11b27c4df94

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0913df460a012f18035ab72232905a01b6702d71a5b54be9e6ccf4ea90340e2b
MD5 213703541b33ddcec815add953916542
BLAKE2b-256 278f796947df6cbd117783178f6863d1b5da21b629c764cbb0b5e46a383c5fdf

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af75381473f1cced9322e162fd9477ad4296f53362a7aa7744803be2861f550f
MD5 ed0b6c727f5b5e4ee4deae43a9882a79
BLAKE2b-256 86fea53c7d4556150e0bc202154961782f222aee8831158940bb31d039bc4114

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84d28ae32f1c4b56e7b5fe4bffc4c152bf6a72f6b854bfb09ab374aa4d621e30
MD5 0e90aa30f7798925fe1521a1d85f3801
BLAKE2b-256 020c25e4f052bcc38659dbdfae27afcf8fc6aa46a6d8223b5530e0a310e73302

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd620e0915cafbc32a379c2bd98e9f2f41fdb2ff60798b34ba378aa0b24449eb
MD5 71b8e27936e7f5de641c9daf28e01e64
BLAKE2b-256 850174146a87630d98c4e1174a86cb28816c7bc2d5c8b6ab6598a4dca3d7eb32

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b5f79a817ba05c728a13f9e52c6683a9aa416ff79d3ec7a77f971b5483f5821
MD5 9288454bc310208637204db5727a53e6
BLAKE2b-256 b26c8989f91c9314bff81dbf8a32603abc3dd11df35cb27782cc5738e9f4889e

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9da52bdb28344ff53e2e8b1197ae28745f1c97f8190ca68fdfb78dfb694fb84
MD5 a4526d2bf2d03547f66b13fcab2084b7
BLAKE2b-256 29319686be3305136d62ed04abb641664c755c006f0235a43c2da2e9ae1db09b

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 90524ca781a0a08f95144c37b2ccfd6b1accf4ce22eee7ed39d88e6ab52cd81b
MD5 1247d912c67c39fdb8eb8777cbd05e6a
BLAKE2b-256 207fa45df0a37a980c09c6ab7a57ceb98c468c4b3db36efbda98d166d167bb42

See more details on using hashes here.

File details

Details for the file pyturso-0.4.0rc9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.0rc9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 be0e29d26cf19c4757c2c347d814b819ac3848b60f89f79940a095299b8ceffb
MD5 6d724b4d1fb6fc4610cee4b16ac3c1e3
BLAKE2b-256 fe3c0131823c80b2be6c549d3e5eb98f7a0f9392b55e72f42ccf4a73dbe54c15

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