Hooks for the beangulp importer.
Project description
hoostus-beangulp-hooks
This is a hook for beangulp, an importer framework for beancount, a Plain Text Accounting system.
This uses machine learning, trained on your previous postings, to predict what the second posting of an imported transaction should be.
That is, the importer will generate something like
2025-03-01 * "Cookie Store"
Assets:AUS:NAB:PersonalAccount -117 AUD
Which is missing the second posting -- the Expense account the spending
went towards. You can enter that second posting manually or use
this hook which will look at your previous transactions to the
"Cookie Store" payee and predict that it should be attributed to
the Expenses:Eating and will modify the resulting import so
that beangulp outputs
2025-03-01 * "Cookie Store"
Assets:AUS:NAB:PersonalAccount -117 AUD
Expenses:Eating
How to use it with beangulp.
The package name in pypi is hoostus-beangulp-hooks so
install it with pypi or add to pyproject.toml with that name.
pip install hoostus-beangulp-hooks
or
dependencies = [
"hoostus-beangulp-hooks"
]
The easiest way.
- Import it:
from hoostus.beangulp.hooks import predict_posting - Add the
simple_hookto the list of hooks you send to beangulp.
In the importer.py you use with beangulp this might look something like:
from hoostus.beangulp.hooks import predict_posting
if __name__ == '__main__':
importers = [ ... ]
hooks = [predict_posting.simple_hook]
ingest = beangulp.Ingest(importers, hooks)
ingest()
If you want to configure it.
Use predict_posting.hook directly and pass in a map of weights
and a list of denied accounts -- accounts you don't want to use for
training the machine learning model. Note that beangulp expects hooks to take
2 parameters but predict_posting.hook takes 4 parameters. This
means you will need to use functools.partial (or similar) to wrap it.
In the importer.py you use with beangulp this might look something like:
from hoostus.beangulp.hooks import predict_posting
import functools
if __name__ == '__main__':
importers = [ ... ]
my_weights = {'meta.category': 0.8, 'payee': 0.5}
my_denied_accounts = ['Expenses:Donuts']
my_hook = functools.partial(predict_posting.hook, my_weights, my_denied_accounts)
hooks = [my_hook]
ingest = beangulp.Ingest(importers, hooks)
ingest()
If you want to reuse the default weights (e.g. to only provide a denied_list)
it is at predict_posting.default_weights. Like so
from hoostus.beangulp.hooks import predict_posting
import functools
if __name__ == '__main__':
importers = [ ... ]
my_denied_accounts = ['Expenses:Donuts']
my_hook = functools.partial(predict_posting.hook, predict_posting.default_weights, my_denied_accounts)
hooks = [my_hook]
ingest = beangulp.Ingest(importers, hooks)
ingest()
Implementation Notes
The training is done on a per-account basis. Only transactions from the imported_account are considered.
Transactions involving closed accounts are removed from the training data.
Any transactions in the training data with a single leg are removed. This isn't valid beancount syntax anyway and is an artifact of (what I believe to be) a bug in beangulp which adds all of the recently imported transactions into the list of existing entries provided to hooks. This muddies the training data, in some cases making it useless.
This is basically recycled from https://github.com/beancount/smart_importer but adapted to the beangulp framework
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hoostus_beangulp_hooks-1.0.3.tar.gz.
File metadata
- Download URL: hoostus_beangulp_hooks-1.0.3.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
849d2109c5cbcb0e402e9eeff3889f306649c542c75646f7007d320e411a8e08
|
|
| MD5 |
8bb5f0e3c914738628686e79b158581c
|
|
| BLAKE2b-256 |
e7b600d37f529417b4464159f6d70cdbe29781d6555861618cfa730c0e95a103
|
File details
Details for the file hoostus_beangulp_hooks-1.0.3-py3-none-any.whl.
File metadata
- Download URL: hoostus_beangulp_hooks-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6947733cdfa0d27540f58e9253c5a264a745fdbcc934ec7453a5f0017b44a92e
|
|
| MD5 |
452e930f0ef10bbf1e374f3563184462
|
|
| BLAKE2b-256 |
f2757064dbf2986357a305246409202083e82ede126e0edd63d7b39344156304
|