import pandas as pd
conn = sqlite3.connect(db_file, isolation_level=None,
detect_types=sqlite3.PARSE_COLNAMES)
db_df = pd.read_sql_query("SELECT * FROM table", conn)
db_df.to_csv('database.csv', index=False)
-- set output to a csv file
sqlite> .mode csv
sqlite> .output test.csv
sqlite> select * from tbl1;
-- revert output to stdout
sqlite> .output stdout