g2b


Nameg2b JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryInitialize a beancount ledger from a GnuCash file
upload_time2024-05-17 19:34:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2024 dtrai2 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords gnucash beancount finance accounting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Gnucash to Beancount

This project can convert a [Gnucash](https://github.com/Gnucash/gnucash) sql file into a new
[beancount](https://github.com/beancount/beancount) file.
It is not intended to continuously import gnucash data into an existing beancount ledger, as this
script will also add plugins and beancount options to the beginning of the file.
This project started with the intention to convert a gnucash csv export, but it turned out that the
csv exported from gnucash is not quite reliable.
Read more about that at in the section [Unreliable Export](#unreliable-gnucash-csv-export).
Because of that I refactored it to use the [piecash](https://pypi.org/project/piecash/) library.
With that it has the same goal as the already existing repository from
[henriquebastos/gnucash-to-beancount](https://github.com/henriquebastos/gnucash-to-beancount).
The implementation in this repository does offer few configuration options though.

One downside I have encountered sofar are stock splits.
Those are currently not supported and have to be added manually to the output by following the
official documentation
[Beancount Stock Splits](https://beancount.github.io/docs/trading_with_beancount.html#stock-splits).
Luckily those splits don't happen too often.

## Prerequisite

Your gnucash file must be in a sql format.
I implemented it with a sqlite3 file, which was saved by GnuCash v5.4.
If your current genucash file is not in the right format it is always possible to just save it
as a sqlite3 file.

## Install

To install `gnucash to beancount` simply use `pip`:

```bash
pip install g2b
```

Test with `g2b --version` if the installation was successful.

## Usage

### Create Configuration for g2b

In order for a successful conversion you need to create a `yaml` configuration file.
An example would look like this:

```yaml
converter:
  loglevel: INFO
gnucash:  # here you can specify details about your gnucash export
  default_currency: EUR
  thousands_symbol: "."
  decimal_symbol: ","
  reconciled_symbol: "b"
  not_reconciled_symbol: "n"
  account_rename_patterns:  # Here you can rename accounts that might not align with the beancount format
    - ["OpenBalance", "Equity:Opening-Balance"]
    - ["Money@[Bank]", "Assets:Money at Bank"]
  non_default_account_currencies:  # Here you have to name all accounts that deviate from the default currency
    Assets:Cash:Wallet: "NZD"
beancount:  # here you can add beancount options, plugins and events that should be added to output file
  flag_postings: false  # if false, will set all transactions automatically to '*' (default: true)
  options:
    - ["title", "Exported GnuCash Book"]  # options should be key value pairs
    - ["operating_currency", "EUR"]
  plugins:
    - "beancount.plugins.check_commodity"  # plugins can be named directly
    - "beancount.plugins.coherent_cost"
    - "beancount.plugins.nounused"
    - "beancount.plugins.auto"
  events:
    2024-05-05: type description string  # optional events that should be added to the output, the
                                         # first space is used to split between space and description
fava:  # optional configuration specific to fava
  commodity-precision: 3  # set the render precision of values for the fava web-frontend
```

## Execute g2b

Once you created the needed configuration file you can call:

```bash
g2b -i book.gnucash -c config.yaml -o my.beancount
```

The script will, at the end, automatically call beancount to parse and verify the export, such
that you know if the conversion was successful or not.

## Limitations

Currently, this project can not deal with stock splits.
Those will not be added to the beancount output and have to be added manually.
To do that follow the official
[Documentation](https://beancount.github.io/docs/trading_with_beancount.html#stock-splits).

## Unreliable Gnucash CSV Export

While starting out with CSV exports I found the following issues that kept me from
progressing with the CSV exports.

- The gnucash csv export does not offer reliable currency information.
  Transaction with values like `100 $` cannot be properly understood as it, for example, could be
  USD or NZD.
  An offical bug report is open since 2017:
  [gnucash bug - use ISO 4217 currency symbols in output](https://bugs.gnucash.org/show_bug.cgi?id=791651).
- The `Rate/Price` value is sometimes added to the wrong posting in transactions with multiple
  currencies.
  Because of that it wasn't easily recognizable how to convert which prices.
- And probably the most severe issue: Some transactions were completely missing inside the export.
  As I couldn't figure out why I decided to use the `piecash` library.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "g2b",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "gnucash, beancount, finance, accounting",
    "author": null,
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# Gnucash to Beancount\n\nThis project can convert a [Gnucash](https://github.com/Gnucash/gnucash) sql file into a new\n[beancount](https://github.com/beancount/beancount) file.\nIt is not intended to continuously import gnucash data into an existing beancount ledger, as this\nscript will also add plugins and beancount options to the beginning of the file.\nThis project started with the intention to convert a gnucash csv export, but it turned out that the\ncsv exported from gnucash is not quite reliable.\nRead more about that at in the section [Unreliable Export](#unreliable-gnucash-csv-export).\nBecause of that I refactored it to use the [piecash](https://pypi.org/project/piecash/) library.\nWith that it has the same goal as the already existing repository from\n[henriquebastos/gnucash-to-beancount](https://github.com/henriquebastos/gnucash-to-beancount).\nThe implementation in this repository does offer few configuration options though.\n\nOne downside I have encountered sofar are stock splits.\nThose are currently not supported and have to be added manually to the output by following the\nofficial documentation\n[Beancount Stock Splits](https://beancount.github.io/docs/trading_with_beancount.html#stock-splits).\nLuckily those splits don't happen too often.\n\n## Prerequisite\n\nYour gnucash file must be in a sql format.\nI implemented it with a sqlite3 file, which was saved by GnuCash v5.4.\nIf your current genucash file is not in the right format it is always possible to just save it\nas a sqlite3 file.\n\n## Install\n\nTo install `gnucash to beancount` simply use `pip`:\n\n```bash\npip install g2b\n```\n\nTest with `g2b --version` if the installation was successful.\n\n## Usage\n\n### Create Configuration for g2b\n\nIn order for a successful conversion you need to create a `yaml` configuration file.\nAn example would look like this:\n\n```yaml\nconverter:\n  loglevel: INFO\ngnucash:  # here you can specify details about your gnucash export\n  default_currency: EUR\n  thousands_symbol: \".\"\n  decimal_symbol: \",\"\n  reconciled_symbol: \"b\"\n  not_reconciled_symbol: \"n\"\n  account_rename_patterns:  # Here you can rename accounts that might not align with the beancount format\n    - [\"OpenBalance\", \"Equity:Opening-Balance\"]\n    - [\"Money@[Bank]\", \"Assets:Money at Bank\"]\n  non_default_account_currencies:  # Here you have to name all accounts that deviate from the default currency\n    Assets:Cash:Wallet: \"NZD\"\nbeancount:  # here you can add beancount options, plugins and events that should be added to output file\n  flag_postings: false  # if false, will set all transactions automatically to '*' (default: true)\n  options:\n    - [\"title\", \"Exported GnuCash Book\"]  # options should be key value pairs\n    - [\"operating_currency\", \"EUR\"]\n  plugins:\n    - \"beancount.plugins.check_commodity\"  # plugins can be named directly\n    - \"beancount.plugins.coherent_cost\"\n    - \"beancount.plugins.nounused\"\n    - \"beancount.plugins.auto\"\n  events:\n    2024-05-05: type description string  # optional events that should be added to the output, the\n                                         # first space is used to split between space and description\nfava:  # optional configuration specific to fava\n  commodity-precision: 3  # set the render precision of values for the fava web-frontend\n```\n\n## Execute g2b\n\nOnce you created the needed configuration file you can call:\n\n```bash\ng2b -i book.gnucash -c config.yaml -o my.beancount\n```\n\nThe script will, at the end, automatically call beancount to parse and verify the export, such\nthat you know if the conversion was successful or not.\n\n## Limitations\n\nCurrently, this project can not deal with stock splits.\nThose will not be added to the beancount output and have to be added manually.\nTo do that follow the official\n[Documentation](https://beancount.github.io/docs/trading_with_beancount.html#stock-splits).\n\n## Unreliable Gnucash CSV Export\n\nWhile starting out with CSV exports I found the following issues that kept me from\nprogressing with the CSV exports.\n\n- The gnucash csv export does not offer reliable currency information.\n  Transaction with values like `100 $` cannot be properly understood as it, for example, could be\n  USD or NZD.\n  An offical bug report is open since 2017:\n  [gnucash bug - use ISO 4217 currency symbols in output](https://bugs.gnucash.org/show_bug.cgi?id=791651).\n- The `Rate/Price` value is sometimes added to the wrong posting in transactions with multiple\n  currencies.\n  Because of that it wasn't easily recognizable how to convert which prices.\n- And probably the most severe issue: Some transactions were completely missing inside the export.\n  As I couldn't figure out why I decided to use the `piecash` library.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 dtrai2  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Initialize a beancount ledger from a GnuCash file",
    "version": "0.2.0",
    "project_urls": {
        "Documentation": "https://github.com/dtrai2/gnucash-csv-to-beancount/blob/main/README.md",
        "Homepage": "https://github.com/dtrai2/gnucash-csv-to-beancount",
        "Issues": "https://github.com/dtrai2/gnucash-csv-to-beancount/issues",
        "Repository": "https://github.com/dtrai2/gnucash-csv-to-beancount"
    },
    "split_keywords": [
        "gnucash",
        " beancount",
        " finance",
        " accounting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "764af754f1b07d672ba193bb9af3d908a931b2a16c69c9a90c82927089630620",
                "md5": "eff289717a4882852b6543266de93d9e",
                "sha256": "377e12e0af2a0e6712caec4ea8ee4068d649da104a002c901ae5c092d3c0b069"
            },
            "downloads": -1,
            "filename": "g2b-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eff289717a4882852b6543266de93d9e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9224,
            "upload_time": "2024-05-17T19:34:34",
            "upload_time_iso_8601": "2024-05-17T19:34:34.862448Z",
            "url": "https://files.pythonhosted.org/packages/76/4a/f754f1b07d672ba193bb9af3d908a931b2a16c69c9a90c82927089630620/g2b-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 19:34:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dtrai2",
    "github_project": "gnucash-csv-to-beancount",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "g2b"
}
        
Elapsed time: 0.24584s