Skip to main content

Beancount Importer for DKB CSV exports

Project description

Beancount DKB Importer

image image Downloads Ruff

beancount-dkb provides importers for converting CSV exports of DKB (Deutsche Kreditbank) account summaries to the Beancount format.

Installation

$ pip install beancount-dkb

In case you prefer installing from the Github repository, please note that main is the development branch so stable is what you should be installing from.

Usage

If you're not familiar with how to import external data into Beancount, please read this guide first.

Beancount 3.x

Beancount 3.x has replaced the config.py file based workflow in favor of having a script based workflow, as per the changes documented here. The beangulp examples suggest using a Python script based on beangulp.Ingest. Here's an example of how that might work:

Add an import.py script in your project root with the following contents:

from beancount_dkb import ECImporter, CreditImporter
from beangulp import Ingest

importers = (
    ECImporter(
        "DE99 9999 9999 9999 9999 99",
        'Assets:DKB:EC',
        currency='EUR',
    ),

    CreditImporter(
        "9999 9999 9999 9999",
        'Assets:DKB:Credit',
        currency='EUR',
    )
)

if __name__ == "__main__":
    ingest = Ingest(importer)
    ingest()

... and run it directly using python import.py extract.

Beancount 2.x

Adjust your config file to include ECImporter and CreditImporter (depending on what account you're trying to import).

Add the following to your config.py.

from beancount_dkb import ECImporter, CreditImporter

CONFIG = [
    ECImporter(
        "DE99 9999 9999 9999 9999 99",
        "Assets:DKB:EC",
        currency='EUR',
    ),

    CreditImporter(
        "9999 9999 9999 9999",
        "Assets:DKB:Credit",
        currency='EUR',
    )
]

Once this is in place, you should be able to run bean-extract on the command line to extract the transactions and pipe all of them into your Beancount file.

$ bean-extract /path/to/config.py transaction.csv >> you.beancount

Transaction Codes as Meta Tags

By default, the ECImporter prepends the transaction code ("Buchungstext") to the transaction description. To achieve shorter descriptions and use meta tags to query for certain transaction codes, the importer may be configured to store the transaction code in a user provided meta tag.

Add the meta_code parameter when instantiating an ECImporter.

Beancount 3.x

from beancount_dkb import ECImporter
from beangulp import Ingest

importers = (
    ECImporter(
        "DE99 9999 9999 9999 9999 99",
        "Assets:DKB:EC",
        meta_code="code',
    ),
)

if __name__ == "__main__":
    ingest = Ingest(importer)
    ingest()

Beancount 2.x

...
CONFIG = [
    ECImporter(
        IBAN_NUMBER,
        'Assets:DKB:EC',
        currency='EUR',
        meta_code='code',
    ),
...

This is how an example transaction looks without the option:

2021-03-01 * "Kartenzahlung" "XY Supermarket"
    Assets:DKB:EC                        -133.72 EUR

And this is the resulting transaction using meta_code='code'

2021-03-01 * "XY Supermarket"
    code: Kartenzahlung
    Assets:DKB:EC                        -133.72 EUR

Pattern-matching Transactions

It's possible to give the importer classes hints if you'd like them to include a second posting based on specific characteristics of the original transaction.

For instance, if the payee or the description in a transaction always matches a certain value, it's possible to tell the ECImporter or CreditImporter to automatically place a second posting in the returned lits of transactions.

ECImporter

ECImporter accepts payee_patterns and description_patterns arguments, which should be a list of (pattern, account) tuples.

Beancount 3.x
from beancount_dkb import ECImporter
from beangulp import Ingest

importers = (
    ECImporter(
        "DE99 9999 9999 9999 9999 99",
        "Assets:DKB:EC",
        payee_patterns=[
            ("REWE", "Expenses:Supermarket:REWE"),
            ("NETFLIX", "Expenses:Online:Netflix"),
        ],
    ),
)

if __name__ == "__main__":
    ingest = Ingest(importer)
    ingest()
Beancount 2.x
CONFIG = [
    ECImporter(
        IBAN_NUMBER,
        "Assets:DKB:EC",
        currency='EUR',
        payee_patterns=[
            ("REWE", "Expenses:Supermarket:REWE"),
            ("NETFLIX", "Expenses:Online:Netflix"),
        ],
    ),

CreditImporter

CreditImporter accepts a description_patterns argument, which should be a list of (pattern, account) tuples.

Beancount 3.x
from beancount_dkb import CreditImporter
from beangulp import Ingest

importers = (
    ECImporter(
        "9999 9999 9999 9999",
        "Assets:DKB:EC",
        currency="EUR",
        payee_patterns=[
            ("REWE", "Expenses:Supermarket:REWE"),
            ("NETFLIX", "Expenses:Online:Netflix"),
        ],
    ),
)

if __name__ == "__main__":
    ingest = Ingest(importer)
    ingest()
Beancount 2.x
CONFIG = [
    CreditImporter(
        CARD_NUMBER,
        'Assets:DKB:Credit',
        currency='EUR',
        description_patterns=[
            ('REWE', 'Expenses:Supermarket:REWE'),
            ('NETFLIX', 'Expenses:Online:Netflix'),
        ],
    )

Contributing

Contributions are most welcome!

Please make sure you have Python 3.9+ and Poetry installed.

  1. Clone the repository: git clone https://github.com/siddhantgoel/beancount-dkb
  2. Install the packages required for development: poetry install
  3. That's basically it. You should now be able to run the test suite: poetry run task test.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

beancount_dkb-1.6.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

beancount_dkb-1.6.2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file beancount_dkb-1.6.2.tar.gz.

File metadata

  • Download URL: beancount_dkb-1.6.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for beancount_dkb-1.6.2.tar.gz
Algorithm Hash digest
SHA256 7a5aee67cd954625926e148bd46f8166cdec95f13a43e6878eb3e8a21e9dfc06
MD5 1c977702bfda3d41af25d3040bb5379c
BLAKE2b-256 c81d6e5b609846d09019494da5f369864d581d35c0194f08073ffe7ad31a315a

See more details on using hashes here.

Provenance

The following attestation bundles were made for beancount_dkb-1.6.2.tar.gz:

Publisher: release.yml on siddhantgoel/beancount-dkb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file beancount_dkb-1.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for beancount_dkb-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ee9caa0124308ac34b1572dac1ef4776d2feb90f91dd792538a24901682a965
MD5 cde59b400bd8f48342cd0b696b1acf99
BLAKE2b-256 9e8a6b4022e6603f1fa126a669b50c4e62b20a35302e572931697161e8785660

See more details on using hashes here.

Provenance

The following attestation bundles were made for beancount_dkb-1.6.2-py3-none-any.whl:

Publisher: release.yml on siddhantgoel/beancount-dkb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page