Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get sql dump of a database created in sqlite using sqlalchemy

I have data read from json and fed into an sqlite database with proper schema using sql-alchemy in python. (used pd.dataframe.to_sql() for this). I want the database dump (.sql file) of this database. is there any api in sql alchemy that would do this?

like image 383
K.Prithvi Sai Avatar asked Oct 29 '25 19:10

K.Prithvi Sai


1 Answers

Assuming that you have a SQLAlchemy engine object associated with your SQLite database you can simply use Python's iterdump method like so:

con = engine.raw_connection()
with open('C:/Users/Gord/Desktop/dump.sql', 'w') as f:
    for line in con.iterdump():
        f.write('%s\n' % line)
like image 107
Gord Thompson Avatar answered Oct 31 '25 08:10

Gord Thompson