Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read postgresql dump file in Python

I'd like my Python script to read some data out of a postgresql dump file. The Python will be running on a system without postgresql, and needs to process the data in a dump file.

It looks fairly straightforward to parse the CREATE TABLE calls to find the column names, then the INSERT INTO rows to build the contents. But I'm sure there would be quite a few gotchas in doing this reliably. Does anyone know of a module which will do this?

like image 722
xorsyst Avatar asked Jun 26 '26 18:06

xorsyst


1 Answers

So ... 7 years later, there is now a Python package written specifically for this:

pip install pgdumplib

From the PyPI page, pgdumplib is a "Python3 library for reading and writing pg_dump files using the custom format."

like image 125
bitinerant Avatar answered Jun 29 '26 09:06

bitinerant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!