bai2


Namebai2 JSON
Version 0.14.0 PyPI version JSON
download
home_pagehttps://github.com/ministryofjustice/bai2
SummaryBAI2 Parser
upload_time2024-04-04 13:22:40
maintainerNone
docs_urlNone
authorMinistry of Justice Digital & Technology
requires_python>=3.6
licenseMIT
keywords bai2 bookkeeping cash management balance reporting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            bai2
====

Python module for parsing and writing `BAI2`_ files.

**The library is not production ready at the moment** as we don't have enough data to test against, please help us improve it.

Requirements
------------

Only Python 3.7+ is supported.

Installation
------------

.. code-block:: shell

    pip install bai2

Usage
-----

To use bai2 in a project

.. code-block:: python

    from bai2 import bai2

    # parse from a file
    with open(<file-path>) as f:
        bai2_file = bai2.parse_from_file(f)

    # parse from a string
    bai2_file = bai2.parse_from_string(<bai2_as_string>)

    # parse from lines
    bai2_file = bai2.parse_from_lines(<bai2_as_lines>)

The ``parse_from_*`` methods return a ``bai2.models.Bai2File`` object which can be used to inspect the parsed data.

To write a BAI2 file:

.. code-block:: python

    from bai2 import bai2
    from bai2 import models

    bai2_file = models.Bai2File()
    bai2_file.header.sender_id = 'EGBANK'

    bai2_file.children.append(models.Group())

    transactions = [models.TransactionDetail(amount=100)]
    bai2_file.children[0].children.append(models.Account(children=transactions))

    # write to string
    output = bai2.write(bai2_file)

Models
------

Models structure::

    Bai2File
        Bai2FileHeader
        Group
            GroupHeader
            Account
                AccountIdentifier
                TransactionDetail
                AccountTrailer
            GroupTrailer
        Bai2FileTrailer

Section models define a ``header``, a ``trailer`` and a list of ``children`` whilst single models define properties matching the bai2 fields.

Each Model has a ``rows`` property with the original rows from the BAI2 file.

Exceptions
----------

The ``parse`` method might raise 3 exceptions:

1. ``ParsingException``: when the file contains an error and the library can't interpret the data
2. ``NotSupportedYetException``: when the library doesn't support the feature yet
3. ``IntegrityException``: when the control totals or the number of objects reported in the trailers don't match the ones in the file.

Incongruences
-------------

We've noticed that different banks implement the specs in slightly different ways and the parse method might therefore raise an ParsingException.
It is expected to work correctly with files produced by NatWest, RBS, and JP Morgan.

We don't know yet how to deal with these cases as we don't have access to many bai2 files so we can't test it as we would like.
You can help by submitting pull requests with sample bai2 files.

Development
-----------

.. image:: https://github.com/ministryofjustice/bai2/actions/workflows/test.yml/badge.svg?branch=main
    :target: https://github.com/ministryofjustice/bai2/actions/workflows/test.yml

.. image:: https://github.com/ministryofjustice/bai2/actions/workflows/lint.yml/badge.svg?branch=main
    :target: https://github.com/ministryofjustice/bai2/actions/workflows/lint.yml

Please report bugs and open pull requests on `GitHub`_.
Please add an item to the `History`_ section to explain code changes.

To work on changes to this library, it’s recommended to install it in editable mode into a virtual environment,
i.e. ``pip install --editable .``

Use ``python -m tests`` to run all tests locally.
Alternatively, you can use ``tox`` if you have multiple python versions.

[Only for GitHub team members] Distribute a new version to `PyPI`_ by:

- updating the ``VERSION`` tuple in ``bai2/__init__.py``
- adding a note to the `History`_
- publishing a release on GitHub which triggers an upload to PyPI;
  alternatively, run ``python -m build; twine upload dist/*`` locally

History
-------

0.14.0 (2024-04-04)
    Adds support for charitable organizations/Donor Advised Funds codes 706 and 708 (thanks @coop-nfg).

0.13.0 (2024-01-16)
    Parse bai2 files with empty lines, trailing whitespace (thanks @Isaben).

0.12.0 (2023-11-16)
    Migrated test, build and release processes away from deprecated setuptools commands.
    No significant library changes.

0.11.0 (2023-02-17)
    Adds support for Real Time Payment detail codes 158 and 458 (thanks @LSakey).

0.10.0 (2023-02-16)
    Improve parsing of account identifier records with respect to varying number of commas used by different banks (thanks @forforeach).

0.9.2 (2023-01-13)
    Maintenance release, no library changes.

0.9.1 (2022-12-22)
    Add support for 829 ‘SEPA Payments’ type code (thanks @podj).

0.9.0 (2022-12-21)
    More lenient parsing where integers are expected (thanks @daniel-butler).
    Add support for 827 & 828 ‘SEPA Payments’ type codes (thanks @podj).
    Remove testing for python versions below 3.7 (the library is still likely to work with 3.6).
    Add testing for python 3.11.

0.8.2 (2022-01-26)
    No library changes.
    Add testing for python 3.9 and 3.10.

0.8.0 (2020-11-11)
    Remove support for python versions below 3.6.

0.7.0 (2019-10-03)
    ``rows`` no longer required in BAI2 models (c.f. issue 12 and PR 13).

0.6.0 (2019-09-18)
    Fix regular expression escaping.
    Add python 3.7 testing.

0.5.0 (2018-03-05)
    Updated packaging details and improved python version compatibility.

0.1.0 (2015-08-06)
    Original release.

Copyright
---------

Copyright (C) 2023 HM Government (Ministry of Justice Digital & Technology).
See LICENSE.txt for further details.

.. _BAI2: https://www.bai.org/docs/default-source/libraries/site-general-downloads/cash_management_2005.pdf
.. _GitHub: https://github.com/ministryofjustice/bai2
.. _PyPI: https://pypi.org/project/bai2/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ministryofjustice/bai2",
    "name": "bai2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "bai2, bookkeeping, cash management, balance reporting",
    "author": "Ministry of Justice Digital & Technology",
    "author_email": "dev@digital.justice.gov.uk",
    "download_url": "https://files.pythonhosted.org/packages/50/67/c91caf4bbfcb07c39f453f8900bd03ee90fb2acf2455503262afb674c6e8/bai2-0.14.0.tar.gz",
    "platform": null,
    "description": "bai2\n====\n\nPython module for parsing and writing `BAI2`_ files.\n\n**The library is not production ready at the moment** as we don't have enough data to test against, please help us improve it.\n\nRequirements\n------------\n\nOnly Python 3.7+ is supported.\n\nInstallation\n------------\n\n.. code-block:: shell\n\n    pip install bai2\n\nUsage\n-----\n\nTo use bai2 in a project\n\n.. code-block:: python\n\n    from bai2 import bai2\n\n    # parse from a file\n    with open(<file-path>) as f:\n        bai2_file = bai2.parse_from_file(f)\n\n    # parse from a string\n    bai2_file = bai2.parse_from_string(<bai2_as_string>)\n\n    # parse from lines\n    bai2_file = bai2.parse_from_lines(<bai2_as_lines>)\n\nThe ``parse_from_*`` methods return a ``bai2.models.Bai2File`` object which can be used to inspect the parsed data.\n\nTo write a BAI2 file:\n\n.. code-block:: python\n\n    from bai2 import bai2\n    from bai2 import models\n\n    bai2_file = models.Bai2File()\n    bai2_file.header.sender_id = 'EGBANK'\n\n    bai2_file.children.append(models.Group())\n\n    transactions = [models.TransactionDetail(amount=100)]\n    bai2_file.children[0].children.append(models.Account(children=transactions))\n\n    # write to string\n    output = bai2.write(bai2_file)\n\nModels\n------\n\nModels structure::\n\n    Bai2File\n        Bai2FileHeader\n        Group\n            GroupHeader\n            Account\n                AccountIdentifier\n                TransactionDetail\n                AccountTrailer\n            GroupTrailer\n        Bai2FileTrailer\n\nSection models define a ``header``, a ``trailer`` and a list of ``children`` whilst single models define properties matching the bai2 fields.\n\nEach Model has a ``rows`` property with the original rows from the BAI2 file.\n\nExceptions\n----------\n\nThe ``parse`` method might raise 3 exceptions:\n\n1. ``ParsingException``: when the file contains an error and the library can't interpret the data\n2. ``NotSupportedYetException``: when the library doesn't support the feature yet\n3. ``IntegrityException``: when the control totals or the number of objects reported in the trailers don't match the ones in the file.\n\nIncongruences\n-------------\n\nWe've noticed that different banks implement the specs in slightly different ways and the parse method might therefore raise an ParsingException.\nIt is expected to work correctly with files produced by NatWest, RBS, and JP Morgan.\n\nWe don't know yet how to deal with these cases as we don't have access to many bai2 files so we can't test it as we would like.\nYou can help by submitting pull requests with sample bai2 files.\n\nDevelopment\n-----------\n\n.. image:: https://github.com/ministryofjustice/bai2/actions/workflows/test.yml/badge.svg?branch=main\n    :target: https://github.com/ministryofjustice/bai2/actions/workflows/test.yml\n\n.. image:: https://github.com/ministryofjustice/bai2/actions/workflows/lint.yml/badge.svg?branch=main\n    :target: https://github.com/ministryofjustice/bai2/actions/workflows/lint.yml\n\nPlease report bugs and open pull requests on `GitHub`_.\nPlease add an item to the `History`_ section to explain code changes.\n\nTo work on changes to this library, it\u2019s recommended to install it in editable mode into a virtual environment,\ni.e. ``pip install --editable .``\n\nUse ``python -m tests`` to run all tests locally.\nAlternatively, you can use ``tox`` if you have multiple python versions.\n\n[Only for GitHub team members] Distribute a new version to `PyPI`_ by:\n\n- updating the ``VERSION`` tuple in ``bai2/__init__.py``\n- adding a note to the `History`_\n- publishing a release on GitHub which triggers an upload to PyPI;\n  alternatively, run ``python -m build; twine upload dist/*`` locally\n\nHistory\n-------\n\n0.14.0 (2024-04-04)\n    Adds support for charitable organizations/Donor Advised Funds codes 706 and 708 (thanks @coop-nfg).\n\n0.13.0 (2024-01-16)\n    Parse bai2 files with empty lines, trailing whitespace (thanks @Isaben).\n\n0.12.0 (2023-11-16)\n    Migrated test, build and release processes away from deprecated setuptools commands.\n    No significant library changes.\n\n0.11.0 (2023-02-17)\n    Adds support for Real Time Payment detail codes 158 and 458 (thanks @LSakey).\n\n0.10.0 (2023-02-16)\n    Improve parsing of account identifier records with respect to varying number of commas used by different banks (thanks @forforeach).\n\n0.9.2 (2023-01-13)\n    Maintenance release, no library changes.\n\n0.9.1 (2022-12-22)\n    Add support for 829 \u2018SEPA Payments\u2019 type code (thanks @podj).\n\n0.9.0 (2022-12-21)\n    More lenient parsing where integers are expected (thanks @daniel-butler).\n    Add support for 827 & 828 \u2018SEPA Payments\u2019 type codes (thanks @podj).\n    Remove testing for python versions below 3.7 (the library is still likely to work with 3.6).\n    Add testing for python 3.11.\n\n0.8.2 (2022-01-26)\n    No library changes.\n    Add testing for python 3.9 and 3.10.\n\n0.8.0 (2020-11-11)\n    Remove support for python versions below 3.6.\n\n0.7.0 (2019-10-03)\n    ``rows`` no longer required in BAI2 models (c.f. issue 12 and PR 13).\n\n0.6.0 (2019-09-18)\n    Fix regular expression escaping.\n    Add python 3.7 testing.\n\n0.5.0 (2018-03-05)\n    Updated packaging details and improved python version compatibility.\n\n0.1.0 (2015-08-06)\n    Original release.\n\nCopyright\n---------\n\nCopyright (C) 2023 HM Government (Ministry of Justice Digital & Technology).\nSee LICENSE.txt for further details.\n\n.. _BAI2: https://www.bai.org/docs/default-source/libraries/site-general-downloads/cash_management_2005.pdf\n.. _GitHub: https://github.com/ministryofjustice/bai2\n.. _PyPI: https://pypi.org/project/bai2/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "BAI2 Parser",
    "version": "0.14.0",
    "project_urls": {
        "Homepage": "https://github.com/ministryofjustice/bai2"
    },
    "split_keywords": [
        "bai2",
        " bookkeeping",
        " cash management",
        " balance reporting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aad0767f9275a9290bcd3a7aeef38c16a70c371d18b057694eab1cc5027684e7",
                "md5": "ca8f8060d1da686b2098d2d7338d5847",
                "sha256": "8cd20390ee64b06a62a2b44a394d6cc031254adc7f9e4f1287d34f748673880e"
            },
            "downloads": -1,
            "filename": "bai2-0.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ca8f8060d1da686b2098d2d7338d5847",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 19536,
            "upload_time": "2024-04-04T13:22:38",
            "upload_time_iso_8601": "2024-04-04T13:22:38.131095Z",
            "url": "https://files.pythonhosted.org/packages/aa/d0/767f9275a9290bcd3a7aeef38c16a70c371d18b057694eab1cc5027684e7/bai2-0.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5067c91caf4bbfcb07c39f453f8900bd03ee90fb2acf2455503262afb674c6e8",
                "md5": "9775a88699f58558a0ff3e6ef5e3d525",
                "sha256": "716a0f076cc947adcfc0d20d5e244be9dcbc173c0937b9705c9792adb561984b"
            },
            "downloads": -1,
            "filename": "bai2-0.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9775a88699f58558a0ff3e6ef5e3d525",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 27135,
            "upload_time": "2024-04-04T13:22:40",
            "upload_time_iso_8601": "2024-04-04T13:22:40.040844Z",
            "url": "https://files.pythonhosted.org/packages/50/67/c91caf4bbfcb07c39f453f8900bd03ee90fb2acf2455503262afb674c6e8/bai2-0.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-04 13:22:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ministryofjustice",
    "github_project": "bai2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "bai2"
}
        
Elapsed time: 3.42904s