Skip to main content

Compressed SQLite — transparent zstd compression via a custom VFS

Project description

turbolite

Compressed SQLite for Python. Transparent zstd compression via a custom VFS — works with the standard sqlite3 module.

Install

pip install turbolite

Usage

import turbolite

# File-first: /data/app.db is the local page image (turbolite-owned).
# /data/app.db-turbolite/ holds hidden implementation state
# (manifest, cache, staging logs).
conn = turbolite.connect("/data/app.db")
conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")
conn.execute("INSERT INTO users VALUES (1, 'alice')")
conn.commit()

rows = conn.execute("SELECT * FROM users").fetchall()
print(rows)  # [(1, 'alice')]
conn.close()

app.db is turbolite's compressed page image. It is not promised to be opened directly by stock sqlite3. To produce a normal SQLite file the standard sqlite3 CLI can read, use iterdump:

src = turbolite.connect("/data/app.db")
dst = sqlite3.connect("/data/exported.sqlite")
dst.executescript("\n".join(src.iterdump()))
dst.close()
src.close()

Lower-level entry point

If you need direct access to the SQLite extension (e.g. to register multiple per-tenant VFSes from a single connection), call turbolite.load(conn) and use the turbolite_register_file_first_vfs(name, db_path) SQL function yourself. The bare cache_dir-based turbolite_register_vfs(name, cache_dir) is still available for embedders who want to manage the cache layout directly, but new code should use turbolite.connect() or the file-first SQL function.

SQL functions

The extension registers helper SQL functions:

conn.execute("SELECT turbolite_version()").fetchone()
# ('0.1.0',)

How it works

turbolite.load(conn) loads a platform-specific SQLite loadable extension (.so/.dylib) bundled inside the Python package. The extension registers a custom VFS named "turbolite" that transparently compresses pages with zstd.

Your existing sqlite3 code works unchanged — just open with ?vfs=turbolite in a URI connection string.

Build from source

# Build the loadable extension
cd ../..
make ext

# Copy into the package
cp target/release/turbolite.dylib packages/python/turbolite/
# or on Linux: cp target/release/turbolite.so packages/python/turbolite/

# Install in development mode
cd packages/python
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turbolite-0.5.0.tar.gz (7.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

turbolite-0.5.0-py3-none-macosx_11_0_universal2.whl (7.5 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file turbolite-0.5.0.tar.gz.

File metadata

  • Download URL: turbolite-0.5.0.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for turbolite-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f8fb34896ad0791b4d846377246dc78674d7b761cd6ba7a92ca4d8f316ea997d
MD5 296e0b8e4dbd06e28dc8c4cfe41bcbc2
BLAKE2b-256 dc4387682e8ef39905a286803f0416dc8edaf7ec3f3263c91c2cd3c737e4cc75

See more details on using hashes here.

File details

Details for the file turbolite-0.5.0-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for turbolite-0.5.0-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 c5ef9fa7711b63a3c0ccff1e82acfab55f082fb09040b79824590e138c9844ef
MD5 198701876a322fd5cb7bb1ce6b4d6f71
BLAKE2b-256 1d81054bcf6f94f7f3f42d7750939cdeb476e8d7af91c9b640b33ef2dc556834

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