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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.3-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.3-cp310-cp310-macosx_11_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.3-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.3.tar.gz.

File metadata

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

File hashes

Hashes for pyturso-0.4.3.tar.gz
Algorithm Hash digest
SHA256 f6a87172831d7a8b531cc1162ae3432ddb9aa3e82cd9c3154534a23570ade434
MD5 7b58252d84c9bd83746794cda2d1ea3b
BLAKE2b-256 fcf29f58c69a53343800c42e417a7725137ca4c0976f78f9de4cf705bd4f9612

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 373851292bb11f0768181e74871acf865e0815d4985c1fbf32d4d4c8fa9a8b07
MD5 12d6a1481415cb726149a07f95ac19c7
BLAKE2b-256 8f602a206b8591b4e7691a55d925fe40c1c8d452192d5992ffb2c02a8a8664fc

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffead7bad7ea87c9167654d1afc9fd31a007d5a686ab0f2b8f09bfbb8d92ef3a
MD5 c6bfecd9030fa2a7de66aed4e4cce5f6
BLAKE2b-256 3b2a5f55c89662ee486b993f7a500eeffe9709531dcf61f5472abbf30746a020

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8fd3b99b4595fc52e854dc1d2c382860cb3eb72f483710faf84d3a601be03f40
MD5 93489a2d19aed2bfb1fecfe1e9efa382
BLAKE2b-256 b2be74740d2af92f52ed846a04c66bf33fb8fefc6c8ef552abccb79b484c5301

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7eb521adba4aa08f823ca434463f93068cb3608d776112151b7f2b70fc723adc
MD5 9cd8363fb4724628adf43d38eef4d3c4
BLAKE2b-256 4cd411ca6c436ef6c9ee65dc8f38985ef3cb7f37a7bfac79fb3a2f5adb8cdba4

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a77ee589a4c96c0f03c6392a36214bf91bb5fd323c444be202a4f2f18538d16
MD5 18e4808a56590ad550462bc263402401
BLAKE2b-256 6ea1b26b90f75b07cf6a7ad1193fb8cbb893e0f09d85c0faf775eda0176ac8ec

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e80672c7c6559f188c9941f119d940feb92234fca56e21d3c0360d2335e8c2a8
MD5 2a827079fa5222ca6d1722663b1dcd4d
BLAKE2b-256 ad97a8ac5e29cb9dfd03960c9573094865a92ccba3b273c7170a9f6eb20e87ac

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8638d639810c075eef27ebed6bb6fb8714e0dc17f1957bbe706f86c18d1235f7
MD5 6ea423c1da2b389ef0c477e2d7e697ee
BLAKE2b-256 5c44fad3e1eb6af3fd32dba9a25dfa1115859bf218a5895a3c3a547d34d7d5cd

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24ca20a7d649b59c0fcabb9079c26c701180a598f2cd631a56029bbcd2f6646e
MD5 6045f84b1b32fa3824c55f59eaaf4964
BLAKE2b-256 8ca7d10904b24be9b1cf731d38691fc9f5012a5dd254dcd45e0c13ee8d2ca578

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a5caea0a5390e7a16b0a32312281d318c64605ad94570d2e36f57fdb0d572ed
MD5 8e46a8306dacfba2e2b046485f4bf944
BLAKE2b-256 873f8aeecd115949197b72c8cc2e97af2f1834c6ea14bfe02ef28c12e242f1e2

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62eb820f1f202d465dff444a027790e1fd1324e50e8934f976335d7b403a8e96
MD5 c2599f84f17729fde6526867177ce846
BLAKE2b-256 b96c0e39d5747d8ae6183b9d4cfcf3876de65509c1b13b8afeb74bdca6c22528

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 797b72e4a0643fabd3a9b8ba4afcd74ff0f352b4291823f8f7386a0c8c2a978f
MD5 852e4c13c0cb90fd2933cfe16b7f6944
BLAKE2b-256 d21331a086853ce4816f695a8ed4622a495f06a5745d96ad4934b15db837b57c

See more details on using hashes here.

File details

Details for the file pyturso-0.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1458288d49b9f8abd0e7a3cd9f8740340be8e3a6e254f70c9201718753232f8c
MD5 063a06edf2c307d24424c000fc906e64
BLAKE2b-256 7ff65f7b841d5f94ee850e0f40928fb8cfeae3f9bee1a1e425e5f64be36771ec

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