I am using GnuCash 2.6.7 under Mac OS X 10.10.4 to do my personal finance. I have a fairly large account structure by now with many expense accounts to track different categories of spending.

I would like to use ledger, or preferably hledger, to work on that data which I have created with GnuCash.

Is there a way to import my accounts, transactions etc into (h)ledger? What is the most painless/recommended way to do it?

  • This is a software question, not a personal finance question. – Derek_6424246 Jul 13 '15 at 15:33
  • 1
    I'm voting to close this question as off-topic because we answer questions about money, we don't offer tech-support for money software – NL - Apologize to Monica Jul 13 '15 at 17:09
  • Derek, Nathan, according to this logic all GnuCash questions should be closed! – user24385 Jul 14 '15 at 15:13
  • 1
    @gojira GnuCash questions that relate to financial features and issues may be on topic, but this question is about data import/export, not financial features, and is best asked at superuser.com. See also this relevant post at our meta site: meta.money.stackexchange.com/questions/9/… – Chris W. Rea Jul 14 '15 at 16:24
  • 1
    @Chris W. Rea: I understand your point, though I disagree, but anyway, can we maybe migrate my question and answer somehow instead of just closing it? I think it is of interest to GnuCash/(h)ledger users who use this for their personal finance. – user24385 Jul 15 '15 at 7:13

Answering my own question, I figured it out: yes, there is a way, with a tool called gnucash2ledger.py.

  • First, save the GnuCash book in sqlite3 format with "Save As..." (if you have an older version of GnuCash, make sure the appropriate database backend is installed).
  • Use this command line tool to convert the sqlite3 books into ledger plain text format: https://github.com/MatzeB/pygnucash
  • For example, if you saved the books in sqlite3 format from within GnuCash as foobar.sqlite3, you can convert it to ledger format like this: python2 gnucash2ledger.py foobar.sqlite3 > foobar.txt
  • Note, this ASCII file will contain the account structure and the actual transactions. With the versions I could use for testing, this leads to errors. I removed the account structure leaving only the actual transaction entries (blocks starting with a date).
  • For hledger, you might need to convert it additionally like this: ledger -f foobar.txt print > foobar.journal

Versions used: GnuCash 2.6.1, Ledger 2.6.2, hledger 0.22