Standard 18 support¶
What the loader reads from a BACS Standard 18 file, where each field sits on a detail record, and how amounts are signed. This page is the README's Features section, included verbatim so the two cannot drift.
Public API¶
from bankstatementparser_loader_bacs import (
BacsStatementParser,
BacsSummary,
load_bacs,
load_bacs_file,
summarize_bacs,
)
| Class / Function | Signature | Returns |
|---|---|---|
load_bacs |
load_bacs(text_or_lines): a str or an iterable of lines |
list[Transaction] |
load_bacs_file |
load_bacs_file(path): a str or os.PathLike |
list[Transaction] |
summarize_bacs |
summarize_bacs(text_or_lines): a str or an iterable of lines |
BacsSummary |
BacsStatementParser |
BacsStatementParser(file_name) |
BankStatementParser with parse() (DataFrame), to_transactions() and get_summary() (dict) |
BacsSummary is a frozen dataclass with the fields service_user_number, originating_sort_code, originating_account, currency (always GBP), submission_date, transaction_count, total_credit and total_debit (both positive Decimals).
Record layout¶
A detail record is a line of at least 30 characters whose first six are digits. The loader reads these columns (1-based, inclusive); tests/test_docs_accuracy.py checks every row of this table against the parser:
| Columns | Field Name | Description |
|---|---|---|
1-6 |
Destination Sort Code | Beneficiary bank sort code |
7-14 |
Destination Account | Beneficiary account number |
15 |
Destination Account Type | Account type digit (not read) |
16-17 |
Transaction Code | 2-character BACS code (99, 01, 17, ...); 99 when the line ends before it |
18-23 |
Originating Sort Code | Service user's (sender's) sort code |
24-31 |
Originating Account | Service user's account number |
32-35 |
Free Format | Not read |
36-46 |
Amount | 11-digit amount in pence |
47-64 |
Originator Name | Service user's name |
65-82 |
Reference | Payment reference |
83-100 |
Destination Name | Beneficiary account name |
101-106 |
Processing Date | Optional: YYDDD (Julian), DDMMYY or YYMMDD; else the UHL1 date |
The UHL1 header gives the file's processing date (columns 5-10) and service user number (11-16). The other labels are skipped.
Mapping to Transaction¶
Transaction field |
Source |
|---|---|
account_id |
<destination sort code>-<destination account>, else the originating account, else BACS |
currency |
Always GBP |
amount |
Pence / 100 as a Decimal, signed by the convention below |
booking_date, value_date |
The processing date, else the UHL1 date |
description |
Debit: the destination name; credit: the originator name (or the destination name, or BACS Transfer); then a hyphen and the reference, unless the text already contains it |
reference |
The reference field, or None when blank |
category |
bacs:<transaction code>, or None when the code is blank |
source, source_index |
"bacs" and the record's position in the file |
Amount and sign convention¶
The amount field holds pence. The loader keeps its ASCII digits (spaces and any other character are dropped; an empty field is 0) and divides by 100 as a decimal.Decimal, never a float.
| Transaction code | Meaning | Sign |
|---|---|---|
01, 17, 18, 19 |
Direct Debit: first, regular, re-presented, final | negative |
anything else (99, Z4, blank, ...) |
Credit | positive |
Errors¶
None of the functions raises on malformed Standard 18 text: a line that is not a record is skipped, a date that does not parse falls back to the UHL1 date, and an amount keeps its ASCII digits. load_bacs_file raises OSError when the file cannot be read; undecodable bytes are replaced, not refused.