Beancount + Pydantic

112 views
Skip to first unread message

Joshua Gilman

unread,
Feb 1, 2022, 10:24:34 AM2/1/22
to bean...@googlegroups.com
While working on an HTTP API backend for beancount, I decided to extract my Pydantic models out into their own package since I believe some people may find it useful to represent core beancount types as Pydantic models. 

bdantic: https://github.com/jmgilman/bdantic

Probably the most useful thing out of the box is you can represent your entire ledger as JSON:
from beancount import loader
from bdantic import parse_loader

result = parse_loader(*loader.load_file("testing/static.beancount"))

print(result.json())
While every model is heavily tested with hypothesis, I've only ingested a few generated beancount ledgers and my own personal one, so there may be additional kinks that need working out.

Additionally, in tandem with the above, I started working out some type stub files for beancount: https://github.com/jmgilman/beancount-stubs. It's still very incomplete but I tried at least getting the core package stubbed out. PRs are welcome for either package :)

Martin Blais

unread,
Feb 15, 2022, 3:12:10 AM2/15/22
to Beancount
Thanks Joshua, I added a link to the contrib doc.
As for stubs, if you wanted to contribute something like that to the Beancount repo that would be welcome.
I'd recommend doing the changes to the Python interfaces directly rather than use .pyi files.



--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAJuQ%3DO0Mj31fONx95qy71vNEij0Uw65%3D-MebhQdeEBrqDQc_%3Dg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages