import sqlite3
new_db = sqlite3.connect(':memory:')
old_db = sqlite3.connect('test.db')
query = ''.join(line for line in old_db.iterdump())
new_db.executescript(query)
How to copy a sqlite table from a disk database to a memory database in python?