Skip to main content
https://travis-ci.org/ministryofjustice/bai2.svg https://coveralls.io/repos/ministryofjustice/bai2/badge.svg?branch=master&service=github

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.4+ supported.

Installation

At the moment, the only way to install the library is from github

pip install git+https://github.com/ministryofjustice/bai2.git

Usage

To use bai2 in a project

>>> 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:

>>> 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.

Please let me know if this happens to you.

History

0.1.0 (2015-08-06)

  • WIP

Download files

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

Source Distribution

bai2-0.2.0.tar.gz (33.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bai2-0.2.0-py2.py3-none-any.whl (21.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file bai2-0.2.0.tar.gz.

File metadata

  • Download URL: bai2-0.2.0.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bai2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 73bd7e23f1a523341ae687e1c93e438ecd007ca3d861a8aaf31385f28dc3714d
MD5 8306a810ad4d9d8b42b10d0225a4477f
BLAKE2b-256 8636651c1ca7a8f3144e636bcca62e11e5b97e8b4685fbb699993c025e9060e2

See more details on using hashes here.

File details

Details for the file bai2-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bai2-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d492dabf96ec1096731d767f6767897d56aa84837ae66f2ca0ab5c12c5fd0203
MD5 3275bd6b90e9f0c8d8cf06070a4f45a9
BLAKE2b-256 f0b9be698d44b7cbcedc0bb44bdaa3dfa03629381e49b5b116ab6f0b7fe80bf5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

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