Skip to main content

beancount-hooks

Rule-based beangulp import hooks for Beancount v3. A Ruleset asserts what a transaction is; predictors then fill only the blanks from the existing ledger. No ML, no runtime dependency beyond Beancount.

Ruleset.hook                 # facts — first match wins
RulesPayeePredictor.hook     # fill an empty payee from the narration
RulesPostingsPredictor.hook  # fill the other leg(s) from history
RulesTagsPredictor.hook      # add tags the payee usually carries

That order is the contract. Reverse it and a guess lands before the rule that should have won.

Install

Requires Python 3.11+ and Beancount 3. After the first release (v0.6.1):

uv add beancount-hooks

Until that tag is on PyPI, install from a checkout:

uv add --editable /path/to/beancount-hooks

Use

from decimal import Decimal as D

from beancount.core.amount import Amount

from beancount_hooks import (
    Actions,
    Match,
    Rule,
    Ruleset,
    RulesPayeePredictor,
    RulesPostingsPredictor,
    RulesTagsPredictor,
)

RULES = [
    Rule(
        Match(payee='Coop'),
        Actions(post='Expenses:Groceries'),
        name='coop',
    ),
    Rule(
        Match(payee='Landlord', sign='debit'),
        Actions(
            post=(
                ('Expenses:Housing:Utilities', Amount(D('150.00'), 'CHF')),
                'Expenses:Housing:Rent',
            ),
            tags=('recurring',),
        ),
        name='rent',
    ),
]

# Limit the ruleset to the importers it was written for.  A card that
# already assigns its own accounts is left alone.
LEDGER_RULES = Ruleset(RULES, label='LedgerRules', accounts=('Assets:Bank',))

HOOKS = [
    LEDGER_RULES.hook,
    RulesPayeePredictor().hook,
    RulesPostingsPredictor().hook,
    RulesTagsPredictor().hook,
]

Pass HOOKS to beangulp.Ingest(CONFIG, HOOKS). The same list is what Fava ingest runs.

Match amounts are absolute; direction is sign='debit' or 'credit'. amount=D("10.00") without a sign matches both the charge and the refund — add sign if you mean only one.

Ruleset.shadowed() returns (earlier, unreachable) pairs for rules that can never fire. Ruleset.explain(txn, account) lists every match in precedence order.

Fava

Fava sends the beangulp 4-tuple only to hooks whose annotations contain the literal text Importer. Every hook in this package does. If you wrap hook, keep that word in the signature or Fava will call you with (filename, entries), the importer account will be missing, and map_transactions will raise.

Documentation

Doc What it is
docs/PRD.md Scope, users, non-goals
docs/SAD.md Components, data flow, the posting ladder
docs/glossary.md Shared vocabulary
docs/adr/ Binding decisions

Develop

make install
uv run pre-commit install
make check
make test

make install syncs the lockfile into .venv. pre-commit formats staged files; pre-push runs make check (the same gate CI uses).

make format   # rewrite the tree
make build    # sdist + wheel, no local path sources
make audit    # zizmor over the workflows

Release

uv version --bump patch   # or minor / major
git add pyproject.toml uv.lock
git commit -m "Release 0.6.2"
git tag v0.6.2
git push origin main --tags

The tag must equal v plus the version in pyproject.toml. A mismatch fails before any PyPI contact. That tag push is the only publish trigger.

Metadata

Release files for beancount-hooks 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beancount-hooks 0.7.0
File Size Uploaded Provenance Actions
beancount_hooks-0.7.0.tar.gz 21.9 kB With provenance Details for beancount_hooks-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for beancount-hooks 0.7.0
File Interpreter ABI Platform Actions
beancount_hooks-0.7.0-py3-none-any.whl Python 3 none any Details for beancount_hooks-0.7.0-py3-none-any.whl

Total release size: 47.9 kB

Release files / beancount_hooks-0.7.0.tar.gz

Download URL beancount_hooks-0.7.0.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
78fe47c7428def7837c9b1f9305d549db999fcb3c228df06fd3e64fdb21bb5e2
BLAKE2b-256 checksum
How to use checksums
bca90a2fe1a7560ccdce7b6d645ae8ab47445df3f88ce07729f34114b67b7ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release files / beancount_hooks-0.7.0-py3-none-any.whl

Download URL beancount_hooks-0.7.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bab9cb85446a7cf77784b91fa69be4f164f61e877239afed8d161096da6df880
BLAKE2b-256 checksum
How to use checksums
5736f3aa7819ae49f06e9dc923e4da53a1cdcd2eb8dedd611ef4bcb951b2a245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Security for beancount-hooks 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for beancount_hooks-0.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page