Use Piecash to interact with GnuCash SQL files
masterPiecash provides a Pythonic interface for accessing and modifying GnuCash files stored in SQL databases (sqlite3, Postgres, and MySQL). It allows you to open existing documents, modify or add objects (such as accounts, transactions, and prices), or create new documents from scratch. It is a pure Python package and serves as an alternative to official Python bindings or XML parsing.
from piecash import open_book
with open_book("example.gnucash") as book:
# Access objects within the book
print(book.default_currency)