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_opts=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.0rc15.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.0rc15-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pyturso-0.4.0rc15-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: pyturso-0.4.0rc15.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.0rc15.tar.gz
Algorithm Hash digest
SHA256 cc6bed7780d2a79b3e43c96334edb35737641aa4123732fd783be427739e1332
MD5 4e31f3b044a48d77a1236b9665f0490c
BLAKE2b-256 6a722dc23a2200059949acb1d67e1e138338d1326eff34538c5d5f0390b2ca03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06eea3c14dd641586b200c8a761444124ee434af695c993de164d94c1ffe179a
MD5 b027f79e37f0d19f63c6bbe0d35f6e07
BLAKE2b-256 1b138ecd6c674654196657462e7ce7dbf8645128ef9c09d7b9f55f4621306e5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d6799d37c4a66723e4a7c9a3e4d16457a09bf4ca817639ce4466f68c1cd6706
MD5 946f00168785a835536f16a71d1807ec
BLAKE2b-256 fc729e2a302c6469c407046b0fc5095bb45e113ecf5cf7c39f649bbc64bf9eaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18eb6f3a5445ea67d2343f680496c6644eca5f3cff0096dac4ecdde7fcbf9693
MD5 e44d0e04f9c42118370ead9c0c3a909a
BLAKE2b-256 b8baceb5d398ae62e080d6df5f6af47bae54cc584e22411e225f0fb8fbf80b02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76d38169b7a0ae7c072f2bbd31d8b0d044b973bcedaa0ccc632dedf061b64d57
MD5 f0125c50e46ca5ebe2ce5f98300ae478
BLAKE2b-256 ae63f18db6b8d90eadda4a203c37e985c32ed895d4226ed4d8b20ec368b1033e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d20793381389d5696958336777e1c43334bbc26d4c0c6db6eb4ff07ce6d665a3
MD5 263f9ab757904774f00390c0b4f2394e
BLAKE2b-256 2ff1f03856025f8000bdb410aa8c9beeee2ecf0da9b46bf4432952baf43f8743

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e88ad685ae7a9ee46f5727aecfd45e8c2f3fa04e822d02608baee195a8204b72
MD5 64f461e9c668ba0d85a7c59e84cbc1e6
BLAKE2b-256 839e0476b347df134a465174f0592d9c782163ab1ad6ce3ccbee1a16c02d7bb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d6094bde6fdd9ead7d8379ddd8459864b1eb9567ff4d786db6ed06fb38ed02c
MD5 b143515b8b996650c0e1729556d0f235
BLAKE2b-256 ae53e30dd7f3542e127b198561de0b4ba6c30ac1449364d45979419414adbab2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37e0685ee31b1148c662fb95464abd8776750d136202b8a774688480397de9c8
MD5 7b031178cb93769c46f04a20db621182
BLAKE2b-256 5203eff11c5ed55b9bab339d858bb8c340401955970191d36100a878cf7faba3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf04e96ab6443b54cd3c95ba7a9d19f20d45f014069ba977a1a11e0511b58f4b
MD5 6275a8fb5c1ba6b6e564a7a1dfcb0ede
BLAKE2b-256 3697ba723497a43e7f76dda29cf5a95aac644b29cf1b22c251d212447f703eb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 106e5e50f1b74e33bff0e37c3e64ad065fa9acb05ec0529cb8e5d1aa43e09604
MD5 98b5bf573d9ff6e779d448cfe550c809
BLAKE2b-256 07aad30e7584c7ee6be29d5f0e2296460b12f97c4fe8417a30a025d179ebca94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de7be394b19ba96e70984a6df03e615856f57849e60a9962b65fa43e092243c3
MD5 a0b45de87963b237271300879b0912b1
BLAKE2b-256 914cfc0406a2664a546375a87a2642697e681446b2fd2ef1b62ce3789700e452

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2f788fbacd9e3d66d2eb1c3e2255eb2896a1423a9d92a08e3f41a94d7adfcdb3
MD5 33b964056dfd5508ce2c01c724c21e7f
BLAKE2b-256 abbef3a86be08f7e4dead9d79489e49f4e8d72e7723451b01c0cbf6bbf4a677b

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