6

In Python, is there a more or less hacky way to open a compressed SQLite database without having to write a temporary file somewhere?

Something like:

import bz2
import sqlite3

dbfile = bz2.BZ2File("/path/to/file.bz2", "wb")
dbconn = sqlite3.connect(dbfile)

cursor = dbconn.cursor()
...

This of course raises:

ValueError: database parameter must be string or APSW Connection object

1 Answer 1

7

The underlying C-library directly uses the filename string. Thus there is no way to transparently work on it from Python.

See the code on Github

Depending on your OS, you might be able to use a RAM-disk to work on the file. If your sqlite-file is bigger than that, it might be time to switch to another DB-system, like Postgres.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, PyFilesystem might be able to give me a cross-platform ramdisk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.