Opening a SQLite database in readonly mode

Joshua Kugler joshua at
Mon Jul 6 22:45:45 CEST 2009

Paul Moore wrote:
> The SQLite documentation mentions a flag, SQLITE_OPEN_READONLY, to
> open a database read only. I can't find any equivalent documented in
> the Python standard library documentation for the sqlite3 module (or,
> for that matter, on the pysqlite library's website).
> Is it possible to open a sqlite database in readonly mode, in Python?

Yes, but most likely not with pysqlite.  The python sqlite3 module in the
standard library, and the pysqlite module are both DB-API compliant, which
means they probably do not have a method to open the DB read only (as that
is usually enforced at the user permission level).

If you want to use that flag, take a look at APSW. It is a very thin layer
on top of the SQLite C API, and thus supports everything that the C API
supports.  It is not, however, DB API compliant, but is very close so not
hard to pick up.

BTW, APSW is written by the same author as pysqlite.


More information about the Python-list mailing list