Giter Club home page Giter Club logo

bai2's Introduction

bai2

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 2.7 and Python 3.3+ are supported.

Installation

pip install bai2

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.

Copyright

Copyright © 2015 HM Government (Ministry of Justice Digital Services). See LICENSE for further details.

bai2's People

Contributors

ibrechin avatar marcofucci avatar ushkarev avatar eranrund avatar stevemarshall avatar

Watchers

James Cloos avatar Andrew Jaeger avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.