cursor.execute('select * from test')
csv_path = 'out.csv'
with open(csv_path, 'wb') as csv_file:
    csv_writer = csv.writer(csv_file)
csv_writer.writerow([i[0] for i in cursor.description])
csv_writer.writerows(cursor)
Sqlite3 / python - Export from sqlite to csv text file does not exceed 20k