Python for Accountants: Reviewable Client Work 2026

Use Python for a local accounting reconciliation. Preserve the source file, check control totals and retain exceptions and review notes with the workpaper.

Published
Updated

Python for accountants works best on repeatable checks: read an unchanged export, reconcile it to independent totals and keep the exceptions for review.

Use Python locally when the same spreadsheet steps recur and another accountant needs to reproduce the result. Start with fictional data and a written rule for every change.

Choose a Small Accounting Task

Choose a task with a known answer, such as comparing transaction totals by account with an independent report. Define the entity, currency and reporting period before exporting either record.

A useful first task has a fixed input format and a clear exception. For example, a sales account total that differs from the ledger report needs investigation before the workpaper is accepted.

Keep accounting decisions outside the script. An account name can be made uppercase under an agreed rule. Deciding whether a payment is deductible needs evidence and professional judgement.

Run the example in a local folder approved by your practice. It reads files and writes workpapers without network requests. Client data still needs your practice’s access restrictions and retention arrangements.

For a one-off comparison, a checked workbook can be easier to maintain. Choose a script when repetition justifies documenting it and someone will own changes to the export format.

Build a Reproducible Reconciliation

Build the reconciliation by preserving the input bytes, checking each record and comparing account totals with independent figures. The example below uses Python 3 and its standard library, with no extra packages.

1. Prepare the Fictional Source

Create a folder called python-workpaper. Save this fictional export inside it as source.csv. The spaces and mixed case in the account column are deliberate.

id,account,amount
T001, sales ,100.00
T002,SALES,50.00
T003,fees,-20.00

The fictional source has three transactions totalling $130.00. A separate fictional ledger report shows two SALES records totalling $150.00 and one FEES record totalling negative $20.00.

Those report figures become the expected values in the script. In client work, retain the actual independent report. Copying expected totals from the same export would only prove that the script agrees with itself.

2. Save the Script

Save the following code as reconcile.py in the same folder. The Python CSV documentation describes the reader and writer used here.

import csv
import hashlib
import io
import json
import re
import sys
from collections import defaultdict
from decimal import Decimal
from pathlib import Path

# Fictional independent report: account -> (record count, total).
EXPECTED = {"SALES": (2, Decimal("150.00")),
            "FEES": (1, Decimal("-20.00"))}

source = Path(sys.argv[1]).resolve()
output = Path(sys.argv[2]).resolve()
raw = source.read_bytes()
rows = list(csv.reader(io.StringIO(raw.decode("utf-8-sig")), strict=True))
if not rows or rows[0] != ["id", "account", "amount"]:
    raise ValueError("STOP: expected id,account,amount header")
if not 1 <= len(rows) - 1 <= 100000:
    raise ValueError("STOP: expected 1 to 100000 source records")

totals = defaultdict(lambda: Decimal("0.00"))
counts = defaultdict(int)
seen = set()
for line, row in enumerate(rows[1:], start=2):
    if len(row) != 3:
        raise ValueError(f"STOP: wrong field count at line {line}")
    transaction, account, amount = row
    account = account.strip().upper()
    if not re.fullmatch(r"T[0-9]{3}", transaction) or transaction in seen:
        raise ValueError(f"STOP: invalid or duplicate ID at line {line}")
    if not re.fullmatch(r"[A-Z]{1,20}", account):
        raise ValueError(f"STOP: invalid account at line {line}")
    if not re.fullmatch(r"-?[0-9]{1,12}\.[0-9]{2}", amount):
        raise ValueError(f"STOP: invalid amount at line {line}")
    seen.add(transaction)
    counts[account] += 1
    totals[account] += Decimal(amount)

results = []
exceptions = []
for account in sorted(set(EXPECTED) | set(totals)):
    expected_count, expected_total = EXPECTED.get(account, (0, Decimal("0.00")))
    difference = totals[account] - expected_total
    row = [account, counts[account], expected_count,
           str(totals[account]), str(expected_total), str(difference)]
    results.append(row)
    if counts[account] != expected_count or difference != 0:
        exceptions.append(row)

# Existing folders are refused so an earlier run cannot be overwritten.
output.mkdir()
header = ["account", "actual_rows", "expected_rows",
          "actual_total", "expected_total", "difference"]
for name, records in [("reconciliation.csv", results),
                      ("exceptions.csv", exceptions)]:
    with (output / name).open("x", newline="", encoding="utf-8") as handle:
        writer = csv.writer(handle)
        writer.writerow(header)
        writer.writerows(records)
manifest = {
    "source": source.name,
    "source_sha256": hashlib.sha256(raw).hexdigest(),
    "script_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
    "python": sys.version,
    "source_rows": len(rows) - 1,
    "source_total": str(sum(totals.values(), Decimal("0.00"))),
    "exception_accounts": len(exceptions)
}
with (output / "run.json").open("x", encoding="utf-8") as handle:
    json.dump(manifest, handle, indent=2)
print(f"Rows={len(rows)-1}; total={manifest['source_total']}; "
      f"exception accounts={len(exceptions)}")
sys.exit(1 if exceptions else 0)

The script trims spaces and changes account letters to uppercase. It leaves transaction IDs and amount text unchanged, so unexpected formats stop the run instead of being silently repaired.

Each amount must have two decimal places and at most 12 digits before the decimal point. The script rejects currency symbols and thousands separators. Negative values use a leading minus sign.

Python’s decimal arithmetic keeps these amounts as decimal values. Converting the source to binary floating-point numbers first would lose that benefit.

Record counts accompany totals because two incorrect transactions can cancel each other out. Unique transaction IDs catch repeated records. Neither check proves that the original export contains every transaction the client recorded.

3. Run the Reconciliation

Open a terminal in your python-workpaper folder. Confirm that python3 --version reports Python 3, then run the command below. Use python if that is your machine’s Python 3 command.

python3 reconcile.py source.csv run-01

The output must read Rows=3; total=130.00; exception accounts=0. The new run-01 folder contains reconciliation.csv, exceptions.csv and run.json.

The reconciliation shows FEES at negative $20.00 and SALES at $150.00, each with zero difference. The exception file contains only its header. The input file stays unchanged.

A non-zero exit status means the run needs attention. Account differences produce output files and exit status 1. An invalid source stops before creating the output folder.

Review and Retain the Run

Review the reconciliation against the independent report and keep the complete run with the workpaper. A zero difference proves agreement with the recorded expectations, not that the client’s accounting treatment is correct.

Keep source.csv and reconcile.py beside the output folder. Add the independent report and a short note explaining the entity, reporting period, currency and sign convention.

run.json records the source and script hashes, Python version, record count and source total. SHA-256 hashes identify the bytes used. They do not prove who supplied the file or whether it is complete.

Record the reviewer’s name, review date, exception decisions and approval in the workpaper. Preserve an exception even when there is an acceptable explanation. Save any corrected input as a separate file and use a new output folder.

Prove That a Changed Source Stops

Copy source.csv to source-bad.csv. In the copy, change the amount header to value, then run the command below.

python3 reconcile.py source-bad.csv run-bad

The script must stop with STOP: expected id,account,amount header. It must not create run-bad. Renaming an export column requires a reviewed change to the script or a correctly formatted replacement export.

For an amount-format check, restore the header in the copied file and change 100.00 to 100.OO. The script must stop with an invalid-amount message identifying line 2.

For a reconciliation exception, use a fresh copy with 100.00 changed to 110.00. The output must show $140.00 overall and a SALES difference of $10.00. The exception file must retain that account.

If the output folder already exists, choose a new name. If the source format changes, establish what changed before editing the rules. Never remove a failing check simply to obtain a zero difference.

Have another accountant rerun the retained source with the retained script in a fresh folder. Accept the workpaper when the figures agree and the reviewer has resolved each exception.

One client form. One finished return.

Your client completes one guided form. Tax Genie checks it, chases mistakes and sends the details to your engagement letter and tax software.

See how Tax Genie works

Made for Australian accounting firms

Tax GenieSee how Tax Genie works