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.1rc2.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.1rc2-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.1rc2-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.1rc2-cp314-cp314-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.5.1rc2-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.1rc2-cp313-cp313-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.5.1rc2-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.1rc2-cp312-cp312-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.5.1rc2-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.1rc2-cp311-cp311-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.5.1rc2-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.1rc2-cp310-cp310-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.5.1rc2-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.1rc2.tar.gz.

File metadata

  • Download URL: pyturso-0.5.1rc2.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.1rc2.tar.gz
Algorithm Hash digest
SHA256 5bea2d25981a1ce033482dd862f50c13628ff8e5dd79c288ae0a60a7d71faeb8
MD5 7d61175d47b9f2fc0a97a4af51c11365
BLAKE2b-256 72cacb115f405f672245f74f27942bf818629aae70ab8e51466b66f6f822b4f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dc26ee8d4d4df63c84f3a3dc3e8fbbbf9e0c4a477627487803bfe1c4953ae11
MD5 1278d4475bf0d5d1440e015493a76773
BLAKE2b-256 330fb2bf6060a1a21a1b618a2865d271b9a6d83ead8d4340e00b807e0775bb3f

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 465e9168d8ffb4ffad6cfbb48ddcb3cc73be946726c9e50e4f21180f315b69de
MD5 06809f3528e15afb9ed4ac4a27961c45
BLAKE2b-256 45093102adc229c1ef2f3bb57538f4bb401baa6547fce659038ca7b15b1467da

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7068adf98b8ba60dc01b3117fdb7c762bec734232070f233cd234dd067f38f0
MD5 2c2e4fbf14ab7d7f053da7153a89dd70
BLAKE2b-256 ec937f875a48f9b266678c0da1db8c9c7c4f1987acaea38dbbe1075e5f292641

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 df27822caa36ac3dd40eee880d457b2ddaef744587260e4c12cc61dd943ae5f0
MD5 49b8bbe6c1c6ed3fc4aa24da9b96ea02
BLAKE2b-256 32abd4fce825b964adf6061b988d0f888a551e92b199dffa25969875749a3710

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 82ce89710bccfb11cd5fe0efac7c354a46ef246fd8b7807441190e81928fd8b6
MD5 16fbe2c7c983db3e09da8d77f6e89c71
BLAKE2b-256 34fecdf4c4a27cf6880b5e316baf9dd3523188a6c75bc7ec675008a2aabb95b7

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b61bed95b099ed6e60c0dd19c56fa3c9fac071577fe52a05e4fb9d6c8f5e523d
MD5 67ccf560291149b1c9869a1da140f467
BLAKE2b-256 1492f3f559c9c28e69599b7ca984b0d673434ddfdc3d29c486e9a5b556a9840e

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d13294037da6c201f07ab332fed9c5d49609b132e299f97ee8c9f2f0189dcba9
MD5 add29fa021b5afbe88bb221d9cfe1cea
BLAKE2b-256 1f38a03aaa1fc404b7df00f2c28b8d45815b6bb7ad5b9388931434fd71b3acee

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5036e48500fcdf4cabb8950ff9703d43914cb82ad138975f7b4d8789f6fd9cdc
MD5 0d4a4bceb28fcd9cace104039a213357
BLAKE2b-256 d2f45c52048498efb42e2692902e02013f4f87dbd9262d678a48b696d4faf866

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b432ab15da3742477421ed9754858b919dfe2646a1531fe225cc584debb2379
MD5 788ef51c572ff232bf0658b8237059c4
BLAKE2b-256 0e1f475325046487daa865c3bd8ee9b3944b28c1e10ce921a5da2d256eb3f792

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 871fbcd079e18cbce15a32bbce8be7ac27324506edffeb6463ff72b14cbdb779
MD5 22070b7075ebef13d3f3383c524f6fa7
BLAKE2b-256 4a9b5cabdcae8b136cfc4b2f79c2672753599404cefb4fdc43ec01aec42d4dc5

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28a96e4246bcf389cdbc304bb9072b27d26d5915b6a9ee22102a1abac4638e5d
MD5 5202815497b6e2a4fc4c2be69f01ffc1
BLAKE2b-256 a0d72c7684b6859fc7b9243464f2bb960b0fef200e41f7d33c6291d77691c640

See more details on using hashes here.

File details

Details for the file pyturso-0.5.1rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyturso-0.5.1rc2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3ec114c2a53120fa359934c72d6ef064437f59405958d5df7dbb72420d3fd91
MD5 0b9aea2a66520c55b5010f1db61967ee
BLAKE2b-256 0c3833a884c419503cdb62cb9deeb97dc0d7b11806738f93c307fafba7fa82ef

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