Exporting from hledger to Beancount frustration

Goal: export an hledger file into Beancount format so I can use Fava
Issues: Searching the documentation isn't helping!

The hledger Print command is supposed to do this, but I can't find anything that explains how to use it. This page is both helpful and frustrating: hledger and Beancount - hledger
I'd love some step by step help if anyone has the patience to fill in my knowledge gaps. I know how to use hledger in the command line, but I'm not up on how to search for what I don't know.

Hello Ellane.

First I would type:

hledger --version

to check which version you are running. If it is ≥ 1.32, I would then run

hledger print --output-format=beancount --output-file=my-export.txt

Let us know whether this works!

1 Like

Hi Elaine,

I'm pretty new to this too. TIL HLedger exports to Beancount!

I pretty much followed @f-a's suggestion, with a couple changes

  • added -f my-transactions.ledger to the flags, since I don't keep my ledger in the default location.
  • changed the extension of --output-file from .txt to .beancount

With these two, I had a my-transactions.beancount which I could view in Fava with

fava my-transactions.beancount
2 Likes

p.s: if you open Fava and get met with "Access denied",

Try flushing the socket pools in your browser — see this reddit reply

Thanks for the feedback @Ellane !

Second tier docs like the cookbook (everything other than manuals and primary landing pages) are updated on a best effort basis, and anyone is welcome to help.

In this case, the last paragraph is up to date:

Since hledger 1.32, and especially in hledger 1.40.99+, the best option for exporting from hledger to beancount is hledger's print command, which supports beancount output.

And those two links are supposed to lead you to

Though we should note the links I just pasted above are to the latest and greatest "dev" version of the docs, which is my habit. Normally it's best to look at the doc version corresponding to the hledger version you are using (if reading it on hledger.org, select the version at the top of any manual page).

So did you find those particular docs ? What went wrong ?

PS and the short answer, adding to the others:

  1. make sure you're running the latest hledger release (to benefit from the recent updates noted here)
  2. hledger print -o main.beancount
  3. if hledger says alias options are needed, add those to the command and run again:
    --alias revenues=income --alias 'other assets'=assets ...

Then beancount and fava should work:

$ bean-check main.beancount
$ bean-query main.beancount "SELECT account, units(sum(position)), cost(sum(position)) WHERE account ~ 'Aaa' GROUP BY 1 ORDER BY account;"
$ fava main.beancount
1 Like

Thank you, all! Sounds like I've been giving up too easily, not searching through the documentation.
My problem at the moment is with the aliases I'm using in hledger; Beancount doesn't seem to like them as it's calling them out as not being an Asset, Liability, Expense, Equity, or Income. At the top of my hledger file I have a whole heap of entries like:

alias pay = Assets:Bank:Paycheck
alias x gifts = Expenses:Gifts
alias i interest = Income:Interest

When I go to export the file to Beancount it's rejecting the aliases. Any way around this?

Thank you, it was the short answer I was looking for!

Are you saying I'll need to type out each of my aliases in the command, even though they are listed at the top of the file? I have of 50 of them!

@Ellane: you only need to ensure the top-most account names are the five expected by Beancount. You seem to be using those already, so there's some information we are missing; the place to look more closely is probably the original error message. Was it from hledger or from beancount ? What did it say ? Also check what top-level account names are reported by
hledger accounts -1

And a tip in case you need it: if sharing terminal output on this forum, you can begin and end with a line of three backticks to preserve the text and layout as seen on the terminal.

```
like
this
```

Oh! It worked!! The error message I received wasn't what I thought. It was pointing out that I hadn't declared one of the aliases I was using. This is exciting! Thanks for all your help

1 Like