Virtual postings from python

Skip to first unread message

Ryan Nowakowski

Jul 24, 2022, 4:26:06 PM7/24/22
to Ledger
Hey Folks,

When I do a ledger.read_journal in python on a file with virtual postings,
has_flag(POST_VIRTUAL) returns False. I would expect it to return True.
Here's a bash run with the details:

$ ledger --version
Ledger 3.2.1-20200518, the command-line accounting tool

Copyright (c) 2003-2019, John Wiegley. All rights reserved.

This program is made available under the terms of the BSD Public License.
See LICENSE file included with the distribution for details and disclaimer.

$ python3 --version
Python 3.9.2

$ cat journal.dat
2022-7-24 August 2022 Budget
[Budget:Expenses:Gas] $200.00
[Budget:Equity] -$200.00

$ cat
import ledger

for xact in ledger.read_journal("journal.dat"):
for post in xact.posts():
is_virtual = post.xdata().has_flags(ledger.POST_VIRTUAL)
must_balance = post.xdata().has_flags(ledger.POST_MUST_BALANCE)
print("%r is virtual: %s, must balance: %s" % (post, is_virtual, must_balance))

$ python3 journal.dat
<ledger.Transaction object at 0x7f588b011040>
<ledger.Posting object at 0x7f588b0110a0> is virtual: False, must balance: False
<ledger.Posting object at 0x7f588b011100> is virtual: False, must balance: False

Can anyone spot any issues with what I'm doing? If not, should I file a
bug against ledger?


Ryan N

Martin Michlmayr

Dec 27, 2022, 12:58:09 AM12/27/22
to, Alexis Hildebrandt
Copying Alexis

* Ryan Nowakowski <> [2022-07-24 15:26]:
> --
> ---
> You received this message because you are subscribed to the Google Groups "Ledger" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To view this discussion on the web visit

Martin Michlmayr


Dec 27, 2022, 11:13:05 AM12/27/22
Thanks for reaching out, Ryan,

at first glance this seems to be a valid issue as
`post.xdata().has_flags(ledger.POST_MUST_BALANCE)` returns `False`
when `post.must_balance()` returns `True`.
Using `post.must_balance()` might be a viable interim solution.

Unfortunately there is no `is_virtual()` function on the `Posting`
type and the exposed `has_flags` fails with the following error for me:

did not match C++ signature:
has_flags(supports_flags<unsigned char, unsigned char> {lvalue}, unsigned char)

It would be greatly appreciated if you could file a bug against
ledger for this.


Ryan Nowakowski

Jan 16, 2023, 6:48:36 PMJan 16
On 12/27/22 10:13 AM, Alexis wrote:

> Thanks for reaching out, Ryan,

Yup!  No prob.

> It would be greatly appreciated if you could file a bug against
> ledger for this.
Reply all
Reply to author
0 new messages