Python: open compressed SQLite database

In Python, is there a more or less hackish 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

      

Thank!

+3


source to share


1 answer


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

See the code on Github



Depending on your OS, you can use a RAM disk to work with the file. If your sqlite file is larger than this, it might be time to switch to another DBMS like Postgres.

+1


source







All Articles