Pydantic Models and Enums

Pydantic Models

  • Bai2Model

bai2_reader.src.models.Bai2Model

The model for the BAI2 file, which will be the output of the parser

Parameters:
  • header (FileHeader | None, default: None ) –

    The header record for this file, record code: '01'

  • groups (List[GroupSection], default: <dynamic> ) –

    The groups for this file, which is the list of group sections that follow the header record

  • file_trailer (FileTrailer, default: None ) –

    The file trailer record for this file, record code: '99'

  • FileHeader

bai2_reader.src.models.FileHeader

The header record TransactionType.debit, which will be the first line of the file, record code: '01'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • sender (str) –

    The sender ID

  • receiver (str) –

    The receiver ID

  • file_date (str) –

    The file date

  • file_time (str) –

    The file time

  • file_id (str) –

    The file ID

  • record_length (str | None, default: None ) –

    The record length, which is optional

  • block_size (str | None, default: None ) –

    The block size, which is optional

  • version_number (str | None, default: None ) –

    The version number, which is optional

  • GroupSection

bai2_reader.src.models.GroupSection

The group section for each group, which will contain - the group header record, - the account sections, - and the group trailer record

Parameters:
  • group_header (GroupHeader | None, default: None ) –

    The group header record, record code: '02'

  • accounts (List[AccountSection], default: <dynamic> ) –

    The accounts for this group, which is the list of account sections that follow the group header record

  • group_trailer (GroupTrailer, default: None ) –

    The group trailer record for this group, record code: '98'

  • GroupHeader

bai2_reader.src.models.GroupHeader

The group header record TransactionType.debit, which will be the first line of each group, record code: '02'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • receiver (str) –

    The receiver ID

  • sender (str) –

    The sender ID

  • group_status (GroupStatus | None) –

    The group status code

  • as_of_date (str) –

    The as of date

  • as_of_time (str) –

    The as of time

  • currency_code (str) –

    The currency code

  • as_of_date_modifier (AsOfDateModifier | None, default: None ) –

    The as of date modifier, which is optional

  • AccountSection

bai2_reader.src.models.AccountSection

Account section for each account, which will contain - the account identifier record, - account summary - the transaction sections, - and the account trailer record

Parameters:
  • account_identifier (AccountIdentifier | None, default: None ) –

    The account identifier record, record code: '03'

  • summary (List[Continuation], default: <dynamic> ) –

    The summary of this account, which is the continuation records that follow the account identifier record. all '88' after '03'

  • transactions (List[TransactionSection], default: <dynamic> ) –

    The transactions for this account, which is the list of transaction sections that follow the account identifier record

  • account_trailer (AccountTrailer, default: None ) –

    The account trailer record for this account, record code: '49'

  • AccountIdentifier

bai2_reader.src.models.AccountIdentifier

The account identifier record, which will be the first line of each account, record code: '03'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • account_number (str) –

    The account number

  • currency_code (str | None, default: None ) –

    The currency code, which is optional

  • type_code (str | None, default: None ) –

    The type code, which is optional

  • opening_balance (float | None, default: None ) –

    The opening balance, which is optional

  • item_count (int | None, default: None ) –

    The item count, which is optional

  • fund_type (str | None, default: None ) –

    The fund type, which is optional

  • rest_of_record (str | None, default: None ) –

    The rest of the record, which is optional, this is for the case when there are more fields than expected, we will store the rest of the record in this field for future use

  • TransactionSection

bai2_reader.src.models.TransactionSection

The transaction section for each transaction, which will contain - the transaction detail record - and the continuation records that follow the transaction detail

Parameters:
  • transaction (Transaction) –

    The transaction detail, record code: '16'

  • summary (List[Continuation], default: <dynamic> ) –

    The summary of this transaction, which is the continuation records that follow the transaction detail record

  • Transaction

bai2_reader.src.models.Transaction

The transaction record which will be the line of each transaction. '16' record code

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • type_code (str) –

    The type code for this transaction

  • amount (float) –

    The amount for this transaction

  • funds_type (str | None, default: None ) –

    The funds type for this transaction, which is optional

  • bank_reference_number (str | None, default: None ) –

    The bank reference number for this transaction, which is optional

  • customer_reference_number (str | None, default: None ) –

    The customer reference number for this transaction, which is optional

  • description (str | None, default: None ) –

    The text for this transaction, which is optional

  • transaction_type (TransactionType, default: None ) –

    The transaction type for this transaction, which is optional

  • rest_of_record (str | None, default: None ) –

    The rest of the record, which is optional, this is for the case when there are more fields than expected, we will store the rest of the record in this field for future use

  • AccountTrailer

bai2_reader.src.models.AccountTrailer

The account trailer record which will be the last line of each account, record code: '49'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • account_control_total (float | None, default: None ) –

    The account control total, which is optional

  • num_of_records (int | None, default: None ) –

    The number of records for this account, which is optional

  • GroupTrailer

bai2_reader.src.models.GroupTrailer

The group trailer record TransactionType.debit, which will be the last line of each group, record code: '98'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • group_control_total (float | None, default: None ) –

    The group control total, which is optional

  • num_of_accounts (int | None, default: None ) –

    The number of accounts for this group, which is optional

  • num_of_records (int | None, default: None ) –

    The number of records for this group, which is optional

  • FileTrailer

bai2_reader.src.models.FileTrailer

The file trailer record TransactionType.debit, which will be the last line of the file, record code: '99'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • file_control_total (float | None, default: None ) –

    The file control total, which is optional

  • num_of_groups (int | None, default: None ) –

    The number of groups for this file, which is optional

  • num_of_records (int | None, default: None ) –

    The number of records for this file, which is optional

  • Continuation

bai2_reader.src.models.Continuation

The continuation record, which will be the line of each continuation, record code: '88'

Parameters:
  • record_code (str) –

    The record code for this line

  • record_counter (int) –

    The record counter for this line, this is internally calculated, not seen in BAI2 file

  • record (str) –

    The continuation record, which will be used when the record is too long and needs to be continued in the next line


Enumerations

  • Record

bai2_reader.src.enums.Record

An enumeration representing the different types of records in a BAI2 file.

account_identifier = '03' class-attribute instance-attribute

account_trailer = '49' class-attribute instance-attribute

continuation = '88' class-attribute instance-attribute

file_header = '01' class-attribute instance-attribute

file_trailer = '99' class-attribute instance-attribute

group_header = '02' class-attribute instance-attribute

group_trailer = '98' class-attribute instance-attribute

transaction = '16' class-attribute instance-attribute

  • GroupStatus

bai2_reader.src.enums.GroupStatus

An enumeration representing the different group status codes in a BAI2 file.

delete = '3' class-attribute instance-attribute

new = '1' class-attribute instance-attribute

test_only = '4' class-attribute instance-attribute

update = '2' class-attribute instance-attribute

  • AsOfDateModifier

bai2_reader.src.enums.AsOfDateModifier

An enumeration representing the different as-of date modifiers in a BAI2 file.

final_previous_day = '2' class-attribute instance-attribute

final_same_day = '4' class-attribute instance-attribute

interim_previous_day = '1' class-attribute instance-attribute

interim_same_day = '3' class-attribute instance-attribute

  • FundsType

bai2_reader.src.enums.FundsType

An enumeration representing the different funds types in a BAI2 file.

distributed_availability = 'D' class-attribute instance-attribute

distributed_availability_simple = 'S' class-attribute instance-attribute

immediate_availability = '0' class-attribute instance-attribute

one_day_availability = '1' class-attribute instance-attribute

two_day_availability = '2' class-attribute instance-attribute

unknown_availability = 'Z' class-attribute instance-attribute

value_dated = 'V' class-attribute instance-attribute

  • TransactionType

bai2_reader.src.enums.TransactionType

An enumeration representing the different transaction types in a BAI2 file.

credit = 'CR' class-attribute instance-attribute

debit = 'DB' class-attribute instance-attribute

misc = 'M' class-attribute instance-attribute

  • TypeCodeLevel

bai2_reader.src.enums.TypeCodeLevel

An enumeration representing the different type code levels in a BAI2 file.

detail = 'detail' class-attribute instance-attribute

status = 'status' class-attribute instance-attribute

summary = 'summary' class-attribute instance-attribute

  • TypeCodes

bai2_reader.src.enums.TypeCodes

A class representing the different type codes in a BAI2 file, including the transaction type, type level code, and description.

type_codes cached property

Get all Typecode details Thanks to : https://github.com/mrrozz/bai2-codes-csv/blob/master/bai-codes.csv

TypeCode dataclass

A data class representing the details of a type code, including the transaction type, type level code, and description.

Parameters:
  • transaction_type (TransactionType | None, default: None ) –
  • type_level_code (TypeCodeLevel | None, default: None ) –
  • description (str | None, default: '' ) –
description = '' class-attribute instance-attribute
transaction_type = None class-attribute instance-attribute
type_level_code = None class-attribute instance-attribute
__init__(transaction_type=None, type_level_code=None, description='')

get_type_code(type_code, ignore_if_not_found=True)

Get the details of a type code by its code. set ignore_if_not_found to false to raise an exception if the type code is not found, otherwise it will return empty details and log a warning