import sqlite3, sys def hook(s, e): if s == "sqlite3.connect": raise PermissionError sys.addaudithook(hook) sqlite3.Connection(":memory:")