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.0rc17.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.0rc17-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.0rc17-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.0rc17-cp314-cp314-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pyturso-0.4.0rc17-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.0rc17-cp313-cp313-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyturso-0.4.0rc17-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.0rc17-cp312-cp312-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyturso-0.4.0rc17-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.0rc17-cp311-cp311-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyturso-0.4.0rc17-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.0rc17-cp310-cp310-macosx_11_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyturso-0.4.0rc17-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.0rc17.tar.gz.

File metadata

  • Download URL: pyturso-0.4.0rc17.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.0rc17.tar.gz
Algorithm Hash digest
SHA256 3b9a5d39c425c085337f84b1c3e7cfd46ea8a4de439a59c9a04fc6d46538877d
MD5 82edbff5f754e6e87c00535d39b7be52
BLAKE2b-256 ecccaada8d3bd2e67f8d38bad43cec1b72c9eafc6f9e79f5d6bc0b247eee33d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49c685b20e4b0028f9ef900de5e6d65b6b1199be7e458937130eb53967962986
MD5 3a7150405044468eda707df597e7c4c5
BLAKE2b-256 ac0b894c6d09ee6efe84ec6604e5509e3acc012f206004f6fc027a4e64aa7127

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0695a2f4b3a4df7f7e59d603dd5110bd7399c61ddc8437fd2111f8f339718561
MD5 379c5870d8a2db7568473094939ae0fd
BLAKE2b-256 c4aa1a5a8297ee543051ed2d952e67b773bc653243f63ea4354008adca2e7691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1413c95e533bd4e0874da12c16f04f86bc395736a3da73b018f5d4e769779ce2
MD5 11498c9cf18611840afc0b45a4a24ebf
BLAKE2b-256 df5ae5775a9953602090b366b8dce2c4ff07627c787732edb30106e72eeb10e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4642698306a595b74eaaa954dfe2c184edb414988c6cbafe1066535205b711d1
MD5 88ca49fa391298de738724c2bf35583f
BLAKE2b-256 a9940a9ffdbf15c8041aad858839aa77b4237fee65e6a885ffd19776febd6037

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57a0fc0de045412d39e4012da4500b911360a32679c52660e2459ba683c3b909
MD5 71fc22754e694b35eb59f4bdcbc22688
BLAKE2b-256 c186cfcf1baf3d22f8d877e19ab0cb6cb859be808bb2c14fa4c4a48f2a3ecfbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff91db467164feb038aea4f5bc82b801d39953645fccb748041774a3336bca7a
MD5 9ff44a9a9b5694bf690ea37752e37ce3
BLAKE2b-256 5d7df3b3da7b64236f2606599974e7a436a72ec77f3399b47b2c8584ce57fcd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 277b47261efe19431047bfd5e2d043b45a0c66e42cc0329f9125ccf7dd86960a
MD5 7be12cff15466e25de6e565e4d8e2185
BLAKE2b-256 ad9583fb263f9d94dc81764edcd0ae48ceceada3d1a3b53fd58cb7921b342245

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 810cd493b54d190cd2757d1efef1f516aabce9b2ffabe813030b8063dc06e7fd
MD5 cae478001606ecdcdc42a83c4f8e1074
BLAKE2b-256 0df79ae6a015280ea37665b5f98b8ded8884f9e812de1ab16e93bde6c774cb26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e00b8eb77a2a372b99dbda7b445b374be235a70c37527260cea3e020fded842c
MD5 4dfbf4b9c011f60ff13cd5654a2b44b2
BLAKE2b-256 be03acb7e9bf43f38fb59f1956b2bdacc5b8b9e197f179cabefac18425df31fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2517cfea87920baae879d6a63f3ebdbad00d8952c0a8ba02eb33c1dc3f07f04
MD5 6b0fb22e14ca855ec5510ab75eef3f39
BLAKE2b-256 586cc9af43ded31c21e83acd9daf8f0164d96f980ff5513ed71f9f9c252c843c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6dce27dde7abea0fd68d143e7a3658a9d49c4125e564e55b8e0910b6c2e9fcd5
MD5 1fdc0d05d943f8a1fd3a21379d9391ed
BLAKE2b-256 5b837b746c9d2a95151ad2ce7c3dc614d8e431ea96e2430bdd6cb423b3c1c7b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyturso-0.4.0rc17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b10618a9a26ee54fb15aa1ec37d95b78aa7c48650b8af52d5cd4435f119ba086
MD5 88030040e3ccda02fa4508b3ae311991
BLAKE2b-256 507958b440bba675c61f136d817a5d804e1f2a4b1a5b48fb5fba3aa8b7e6147d

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