{"id":13522848,"url":"https://github.com/beancount/smart_importer","last_synced_at":"2025-06-10T17:14:45.811Z","repository":{"id":28014475,"uuid":"112750160","full_name":"beancount/smart_importer","owner":"beancount","description":"Augment Beancount importers with machine learning functionality.","archived":false,"fork":false,"pushed_at":"2025-05-23T19:21:33.000Z","size":347,"stargazers_count":261,"open_issues_count":8,"forks_count":34,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-23T19:42:09.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beancount.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-01T14:39:18.000Z","updated_at":"2025-05-23T19:19:47.000Z","dependencies_parsed_at":"2024-01-13T22:25:10.955Z","dependency_job_id":"0b06870f-6051-4262-a8bc-81bb8f437159","html_url":"https://github.com/beancount/smart_importer","commit_stats":{"total_commits":210,"total_committers":10,"mean_commits":21.0,"dds":0.5428571428571429,"last_synced_commit":"554232c709f730ff6719507b7621d07e8965c6f1"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beancount%2Fsmart_importer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beancount%2Fsmart_importer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beancount%2Fsmart_importer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beancount%2Fsmart_importer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beancount","download_url":"https://codeload.github.com/beancount/smart_importer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beancount%2Fsmart_importer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259114721,"owners_count":22807255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:00:52.942Z","updated_at":"2025-06-10T17:14:45.801Z","avatar_url":"https://github.com/beancount.png","language":"Python","funding_links":[],"categories":["Importers","Python","others"],"sub_categories":["Misc"],"readme":"smart_importer\n==============\n\nhttps://github.com/beancount/smart_importer\n\n.. image:: https://github.com/beancount/smart_importer/actions/workflows/ci.yml/badge.svg?branch=main\n   :target: https://github.com/beancount/smart_importer/actions?query=branch%3Amain\n\nAugments\n`Beancount \u003chttp://furius.ca/beancount/\u003e`__ importers\nwith machine learning functionality.\n\n\nStatus\n------\n\nWorking protoype, development status: beta\n\n\nInstallation\n------------\n\nThe ``smart_importer`` can be installed from PyPI:\n\n.. code:: bash\n\n    pip install smart_importer\n\n\nQuick Start\n-----------\n\nThis package provides import hooks that can modify the imported entries. When\nrunning the importer, the existing entries will be used as training data for a\nmachine learning model, which will then predict entry attributes.\n\nThe following example shows how to apply the ``PredictPostings`` hook to\nan existing CSV importer:\n\n.. code:: python\n\n    from beangulp.importers import csv\n    from beangulp.importers.csv import Col\n\n    from smart_importer import PredictPostings\n\n\n    class MyBankImporter(csv.Importer):\n        '''Conventional importer for MyBank'''\n\n        def __init__(self, *, account):\n            super().__init__(\n                {Col.DATE: 'Date',\n                 Col.PAYEE: 'Transaction Details',\n                 Col.AMOUNT_DEBIT: 'Funds Out',\n                 Col.AMOUNT_CREDIT: 'Funds In'},\n                account,\n                'EUR',\n                (\n                    'Date, Transaction Details, Funds Out, Funds In'\n                )\n            )\n\n\n    CONFIG = [\n        MyBankImporter(account='Assets:MyBank:MyAccount'),\n    ]\n\n    HOOKS = [\n        PredictPostings().hook\n    ]\n\n\nDocumentation\n-------------\n\nThis section explains in detail the relevant concepts and artifacts\nneeded for enhancing Beancount importers with machine learning.\n\n\nBeancount Importers\n~~~~~~~~~~~~~~~~~~~~\n\nLet's assume you have created an importer for \"MyBank\" called\n``MyBankImporter``:\n\n.. code:: python\n\n    class MyBankImporter(importer.Importer):\n        \"\"\"My existing importer\"\"\"\n        # the actual importer logic would be here...\n\nNote:\nThis documentation assumes you already know how to create Beancount/Beangulp importers.\nRelevant documentation can be found in the `beancount import documentation\n\u003chttps://beancount.github.io/docs/importing_external_data.html\u003e`__.\nWith the functionality of beangulp, users can\nwrite their own importers and use them to convert downloaded bank statements\ninto lists of Beancount entries.\nExamples are provided as part of beangulps source code under\n`examples/importers\n\u003chttps://github.com/beancount/beangulp/tree/master/examples/importers\u003e`__.\n\nsmart_importer only works by appending onto incomplete single-legged postings\n(i.e. It will not work by modifying postings with accounts like \"Expenses:TODO\").\nThe `extract` method in the importer should follow the\n`latest interface \u003chttps://github.com/beancount/beangulp/blob/master/beangulp/importer.py\u003e`__\nand include an `existing_entries` argument.\n\nUsing `smart_importer` as a beangulp hook\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nBeangulp has the notation of hooks, for some detailed example see `beangulp hook example \u003chttps://github.com/beancount/beangulp/blob/ead8a2517d4f34c7ac7d48e4ef6d21a88be7363c/examples/import.py#L50\u003e`.\nThis can be used to apply smart importer to all importers.\n\n* ``PredictPostings`` - predict the list of postings.\n* ``PredictPayees``- predict the payee of the transaction.\n\nFor example, to convert an existing ``MyBankImporter`` into a smart importer:\n\n.. code:: python\n\n    from your_custom_importer import MyBankImporter\n    from smart_importer import PredictPayees, PredictPostings\n\n    CONFIG = [\n        MyBankImporter('whatever', 'config', 'is', 'needed'),\n    ]\n\n    HOOKS = [\n        PredictPostings().hook,\n        PredictPayees().hook\n    ]\n\nWrapping an importer to become a  `smart_importer`\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nInstead of using a beangulp hook, it's possible to wrap any importer to become a smart importer, this will modify only this importer.\n\n* ``PredictPostings`` - predict the list of postings.\n* ``PredictPayees``- predict the payee of the transaction.\n\nFor example, to convert an existing ``MyBankImporter`` into a smart importer:\n\n.. code:: python\n\n    from your_custom_importer import MyBankImporter\n    from smart_importer import PredictPayees, PredictPostings\n\n    CONFIG = [\n        PredictPostings().wrap(\n            PredictPayees().wrap(\n                MyBankImporter('whatever', 'config', 'is', 'needed')\n            )\n        ),\n    ]\n\n    HOOKS = [\n    ]\n\n\nSpecifying Training Data\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe ``smart_importer`` hooks need training data, i.e. an existing list of\ntransactions in order to be effective. Training data can be specified by\ncalling bean-extract with an argument that references existing Beancount\ntransactions, e.g., ``import.py extract -e existing_transactions.beancount``. When\nusing the importer in Fava, the existing entries are used as training data\nautomatically.\n\n\nUsage with Fava\n~~~~~~~~~~~~~~~\n\nSmart importers play nice with `Fava \u003chttps://github.com/beancount/fava\u003e`__.\nThis means you can use smart importers together with Fava in the exact same way\nas you would do with a conventional importer. See `Fava's help on importers\n\u003chttps://github.com/beancount/fava/blob/main/src/fava/help/import.md\u003e`__ for more\ninformation.\n\n\nDevelopment\n-----------\n\nPull requests welcome!\n\n\nExecuting the Unit Tests\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nSimply run (requires tox):\n\n.. code:: bash\n\n    make test\n\n\nConfiguring Logging\n~~~~~~~~~~~~~~~~~~~\n\nPython's `logging` module is used by the smart_importer module.\nThe according log level can be changed as follows:\n\n\n.. code:: python\n\n    import logging\n    logging.getLogger('smart_importer').setLevel(logging.DEBUG)\n\n\nUsing Tokenizer\n~~~~~~~~~~~~~~~~~~\n\nCustom tokenizers can let smart_importer support more languages, eg. Chinese.\n\nIf you looking for Chinese tokenizer, you can follow this example:\n\nFirst make sure that `jieba` is installed in your python environment:\n\n.. code:: bash\n\n    pip install jieba\n\n\nIn your importer code, you can then pass `jieba` to be used as tokenizer:\n\n.. code:: python\n\n    from smart_importer import PredictPostings\n    import jieba\n\n    jieba.initialize()\n    tokenizer = lambda s: list(jieba.cut(s))\n\n    predictor = PredictPostings(string_tokenizer=tokenizer)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeancount%2Fsmart_importer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeancount%2Fsmart_importer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeancount%2Fsmart_importer/lists"}