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.0rc7.tar.gz (1.6 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.0rc7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.8 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

pyturso-0.5.0rc7-cp314-cp314-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.0rc7-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.5.0rc7-cp313-cp313-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.0rc7-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.5.0rc7-cp312-cp312-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.0rc7-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.5.0rc7-cp311-cp311-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.0rc7-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.5.0rc7-cp310-cp310-macosx_11_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.0rc7-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.5.0rc7.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.5.0rc7.tar.gz
Algorithm Hash digest
SHA256 75778bd2badc9225548a25a0b123dd2553ddc18d92393991560100f6166d353b
MD5 e12c5a127c789a7dcf810b0bba4b4a49
BLAKE2b-256 876f1ae1e5ee3654515a1e85732b68bcb231eb8ad86274a0269c8b8d43504e25

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8214f21dd18944d3ec7971e6e3feb9a17e211ce816061e355b1b13347916700f
MD5 5b7b52b8664b8f9b64453be715e19e29
BLAKE2b-256 526b16ff2ec37f3448c7ac6b9fdc16ff083297e1a524d69bf8e222635970e815

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 083050435c275e6c1614871659ffa28564df16c1dfb42875d93fe754009fbfb0
MD5 64917026b5d1c54a7e2329b03d5fc33e
BLAKE2b-256 00dc6cc1d2ac94c95060ea00d26736f77d2d585dd334d57e92ff7935447e5e25

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 815697b817838a1fca15fb37da5b879b6e201692aadd76c489a3c80a393724bf
MD5 296f07f98b9e8a4286af80afa04ccc5f
BLAKE2b-256 c3ef1434ff720191e34a6b4b9b678a0aefdb83a15d8cd011d1bd681f28e0280b

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 07aee33fbd210ad5fb0568fa9ec9ddebbcd0d759c91c82bf62e36917a7e83250
MD5 8cfce8d252c091f078494250e7d890ca
BLAKE2b-256 29e49493677d2ac998df94b1e9b4dcee82fb806e5ab4e536251c5e0c874e670e

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 159311b772345f5c80a30e4ce36f1de17edcc8daa00643de176d397b3b74afed
MD5 31b5d87c9a75888934b5bfcbcd380e6d
BLAKE2b-256 beadb78027a84d8b82b5447c68769af90a4946377fb0d4549b3d0bd0b5714680

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6c0dea5d42d4d214c9f76d21c6e1e23e0478ccbe6c5e80265f03bf6bafbfabe2
MD5 25b1830370027b0d9d3193e8fbcd0258
BLAKE2b-256 5e8b993c6a90566f57a953a4cd254c1ee7cb57cc190b5fa973ad03aa99088526

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38e09f6bd923f15eab0e987daa42efbce3d42a24ba3af34a6024daf18cfeedbb
MD5 7e9e67c0286450be3eaf1e3a8b86633f
BLAKE2b-256 65bff1e9ea210d644e47e96704f224850a4900c4e64dab52c293bcbd30beb85b

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09cbdeda3d6f8acc547cd6ef17590f1df310abdae6ec6334ee8e63450d6f0996
MD5 0f17febaa4c3a9e3a566c0fc13390b5e
BLAKE2b-256 524e3163ee33edd4b90e5b1d0fb6ce4855776352bb200b948ca4f92978a3ee1a

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b4bcc31c3e693708b3098c71618a95a5cf85cf3128975ac8c3a54dc81ab42f7
MD5 c3e87ad3b94885b4301c3531b1355068
BLAKE2b-256 ed8c142e6529104ab98735f7aaa286526d1dd36a7a64e8bda20a5282c80272c4

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d9ab3a07cf79ddba26da1dc45a3d2bb50b287de95ebe2c92ec16ecc511d8c75f
MD5 fbca2ef148f5efb00d1a36a9e63b63b6
BLAKE2b-256 90b3e5ac747fd30ab0acde3e3dd710bbc3bf597bad769376c5cffd9d0e06d1ed

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c4a298ccc163b5ccf63902171cd9920a1f2cbd40c4b0083d994ac62215914f5
MD5 8533eb0d40e2a5e25dde89dfd120ab1a
BLAKE2b-256 ed44041ad782ea4430f6d87102bf0234c061dd60fb0ba2eda9a423fb2fbb3dfb

See more details on using hashes here.

File details

Details for the file pyturso-0.5.0rc7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.0rc7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33cde3f16e950ef3c8b0c46f68f47627091a7a1678365fcf5fabb41b4d4ef672
MD5 0fe614f72169410878a0942ab0d24a2a
BLAKE2b-256 2e6c021283a9d86d87cc64962b755ea20590949bdc09b08f29cf54d8045ae41e

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