List of tables, db schema, dump etc using the Python sqlite3 API

noamtm picture noamtm · Nov 20, 2008 · Viewed 192.9k times · Source

For some reason I can't find a way to get the equivalents of sqlite's interactive shell commands:

.tables
.dump

using the Python sqlite3 API.

Is there anything like that?

Answer

Davoud Taghawi-Nejad picture Davoud Taghawi-Nejad · May 25, 2012

In Python:

con = sqlite3.connect('database.db')
cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
print(cursor.fetchall())

Watch out for my other answer. There is a much faster way using pandas.