Skip to main content

Language Server Protocol (LSP) server for linting MT940 bank statement files with the bankstatementparser library.

Project description

bankstatementparser-lsp logo

bankstatementparser-lsp

Language Server Protocol server that lints MT940 bank-statement files as you type, backed by the bankstatementparser library.

PyPI version Python versions PyPI downloads Tests Coverage License


Contents

Getting started

Library reference

Operational


What is bankstatementparser-lsp?

A Language Server speaks the Language Server Protocol (LSP) — the editor-agnostic protocol that lets a single backend deliver diagnostics to any LSP client (VS Code, Neovim, Helix, Emacs, …). bankstatementparser-lsp is that backend for MT940 bank-statement files (.mt940 / .sta): the SWIFT tag-and-line format parsed by the bankstatementparser library.

The diagnostic engine shares the MT940 tag patterns the bankstatementparser parser relies on, so the squiggles you see in the editor match the structure the parser will accept.

Concern How bankstatementparser-lsp handles it
Mandatory tags Flags any missing :20:, :25:, :28C:, :60F:, :62F: tag
Balance lines Validates :60F: / :62F: against C/D + YYMMDD + 3-letter currency + amount
Statement lines Validates :61: against YYMMDD + C/D + amount
Information lines Warns when an :86: line has no preceding :61: statement line
Live linting Re-lints on open and on every change, publishing diagnostics back to the editor

Install

Channel Command Notes
PyPI pip install bankstatementparser-lsp Pulls in bankstatementparser >= 0.0.9 + pygls
Source git clone https://github.com/sebastienrousseau/bankstatementparser-lsp && cd bankstatementparser-lsp && poetry install For development
Docker (GHCR) docker pull ghcr.io/sebastienrousseau/bankstatementparser-lsp:latest Multi-arch (linux/amd64, linux/arm64); runs bankstatementparser-lsp over stdio

Requires Python 3.10 or later. Works on macOS, Linux, and Windows.

Verify the installation:

python -c "import bankstatementparser_lsp; print('bankstatementparser-lsp', bankstatementparser_lsp.__version__)"
# -> bankstatementparser-lsp 0.0.11
Using an isolated virtual environment (recommended)
python -m venv venv
source venv/bin/activate        # macOS/Linux
venv\Scripts\activate           # Windows
python -m pip install -U bankstatementparser-lsp

Quick start

The package installs a bankstatementparser-lsp console entry point that starts the language server over stdio:

bankstatementparser-lsp
# -> (waiting on stdin for LSP JSON-RPC)

The command speaks LSP on stdin/stdout — it is meant to be launched by your editor's LSP client, not used interactively. Wire it up (Editor wiring) and open any MT940 statement file (.mt940 / .sta); diagnostics light up as you type.


Features

For MT940 bank-statement documents (one statement of SWIFT-style :tag: lines), bankstatementparser-lsp publishes diagnostics:

Rule code Severity Behaviour
missing-tag error A mandatory tag (:20:, :25:, :28C:, :60F:, :62F:) is absent
malformed-balance error A :60F: / :62F: balance line does not match C/D + YYMMDD + 3-letter currency + amount
malformed-statement-line error A :61: statement line does not match YYMMDD + C/D + amount
orphan-information-line warning An :86: information line has no preceding :61: statement line

Diagnostics are republished on textDocument/didOpen and textDocument/didChange, so the editor stays in sync on every keystroke. An empty or whitespace-only document produces no diagnostics.

The feature logic lives in a pure, importable engine (diagnostics_for_mt940, returning Diagnostic objects with a Severity); the LSP handlers are thin glue that map those objects to lsprotocol types.


Editor wiring

Register bankstatementparser-lsp as the server cmd for MT940 files in your editor's LSP client. MT940 files commonly use the .mt940 or .sta extension; most editors will need a filetype mapping for them.

Neovim (built-in vim.lsp.config)
-- Map the MT940 extensions to a filetype.
vim.filetype.add({
  extension = {
    mt940 = "mt940",
    sta = "mt940",
  },
})

vim.lsp.config["bankstatementparser"] = {
  cmd = { "bankstatementparser-lsp" },
  filetypes = { "mt940" },
  root_markers = { ".git" },
}
vim.lsp.enable("bankstatementparser")
VS Code (bundled scaffold)

A TypeScript language-client scaffold ships at editors/vscode/ — runnable straight from source:

cd editors/vscode
npm install
npm run compile
# Press F5 in VS Code to launch an Extension Development Host.

bankstatementparser.serverCommand (default bankstatementparser-lsp) is exposed as a setting; the extension activates for .mt940 / .sta files.

Helix / Emacs / generic LSP

Any client that can spawn a stdio language server will work. The command is bankstatementparser-lsp and the documents are MT940 statement files (.mt940 / .sta).


Using the helpers

Because the diagnostic engine is pure, you can call it directly — no editor or server process required. This is exactly what the server runs on each edit:

from bankstatementparser_lsp.diagnostics import diagnostics_for_mt940

# A clean MT940 statement produces no diagnostics.
clean = (
    ":20:STARTUMS\n"
    ":25:1234567890\n"
    ":28C:00001/001\n"
    ":60F:C230101EUR1000,00\n"
    ":61:2301020102C500,00NTRFNONREF//abc\n"
    ":86:Salary payment\n"
    ":62F:C230102EUR1500,00"
)
assert diagnostics_for_mt940(clean) == []

# Missing mandatory tags surface as errors.
diagnostics = diagnostics_for_mt940(":20:ONLY\n:61:2301020102C5,00NTRF")
print(len(diagnostics), "issue(s)")
# -> e.g. "4 issue(s)"

# Each diagnostic carries a 0-based range, a severity, and a rule code.
for d in diagnostics:
    print(d.line, d.code, d.message)
# -> 0 missing-tag Missing mandatory MT940 tag: :25:
#    ...

Each Diagnostic exposes line, col_start, col_end, severity (a Severity enum matching the LSP numeric scale), message, and a stable code — which the server maps to lsprotocol.Diagnostic before publishing.

The runnable version of this snippet lives in examples/01_lsp_helpers.py. See also 02_severity_filtering.py (grouping by severity), 03_lsp_conversion.py (the lsprotocol conversion the server performs), and 04_server_publish.py (the server's lint-and-publish path driven by a fake LanguageServer, so it runs without an editor).


The bankstatementparser suite

bankstatementparser-lsp is part of a set of independently installable packages built around the bankstatementparser library — pick whichever ones your stack needs:

Package Role
bankstatementparser Core library + CLI (MT940 / CAMT parsing)
bankstatementparser-lsp Language Server Protocol server (this package)
flowchart LR
    A["Editor (VS Code / Neovim / …)"] -->|LSP over stdio| B["bankstatementparser-lsp"]
    B -->|diagnostics_for_mt940| C["diagnostic engine (MT940 tag patterns)"]
    C -->|Diagnostic objects| B
    B -->|publishDiagnostics| A

When not to use bankstatementparser-lsp

  • You're not editing MT940 statements. The server targets the SWIFT MT940 tag-and-line format (.mt940 / .sta); for CAMT XML or other formats use a format-appropriate language server.
  • You need full parsing, not editor diagnostics. Use the core bankstatementparser library to parse statements into structured records.

Development

bankstatementparser-lsp uses Poetry and mise.

git clone https://github.com/sebastienrousseau/bankstatementparser-lsp.git
cd bankstatementparser-lsp
mise install
poetry install

A Makefile orchestrates the quality gates (kept in lockstep with CI):

Target What it runs
make check All gates (REQUIRED before commit)
make test pytest --cov=bankstatementparser_lsp --cov-branch --cov-fail-under=100
make lint ruff check + ruff format --check
make type-check mypy --strict
make examples Run the example scripts

Current state (v0.0.11): 50 tests passing, 100% line + branch coverage against a 100% enforced floor, mypy --strict clean, interrogate 100% docstring coverage. The suite includes documentation and example regression tests (tests/test_docs_accuracy.py, tests/test_regression_docs.py, tests/test_regression_examples.py) that execute every documented snippet and every examples/*.py script.


Security

  • No filesystem writes. The server reads from the editor's in-memory document buffer; no scratch files, no temp directories.
  • MT940 parsing is a pure-re line scanner over text from the editor — no eval, no shelling out, no XML, no network.
  • Lint findings are returned as lsprotocol.Diagnostic objects with no stack traces, so the editor never sees an internal path or exception message.
  • Dependencies are pinned via poetry.lock and audited by pip-audit and Bandit in CI.

To report a vulnerability, please use GitHub private vulnerability reporting rather than a public issue.


Documentation


Contributing

Contributions are welcome — see the contributing instructions. Thanks to all the contributors who have helped build bankstatementparser-lsp.


License

Licensed under the Apache License, Version 2.0. Built on pygls and lsprotocol by the Open Law Library, and on the core bankstatementparser library that powers the validators and schemas.

Any contribution submitted for inclusion shall be licensed as above, without additional terms.


bankstatementparser.com · PyPI · GitHub

Project details


Download files

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

Source Distribution

bankstatementparser_lsp-0.0.11.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

bankstatementparser_lsp-0.0.11-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file bankstatementparser_lsp-0.0.11.tar.gz.

File metadata

  • Download URL: bankstatementparser_lsp-0.0.11.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bankstatementparser_lsp-0.0.11.tar.gz
Algorithm Hash digest
SHA256 ab8883c0fb76f4fc27a0a8040c5a7c0126a729c52c66cd2ce1d741876f33ccb5
MD5 3cadb454695553745302447800eb9b58
BLAKE2b-256 9040df39cdeea2d4f393a4ef0ad72f3041fadc4e3d08d34c49c3a8142b1220a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bankstatementparser_lsp-0.0.11.tar.gz:

Publisher: release.yml on sebastienrousseau/bankstatementparser-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bankstatementparser_lsp-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for bankstatementparser_lsp-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 08b1e2ec2c10f937ac6fe015bf772b526d03fee1939bdf86f03a89fd634319ca
MD5 b7f8cdd2579ac8f0ada5ff7593f56eea
BLAKE2b-256 9f5e802adb4cd19a774b2f9dd78a0e712031a994e01047e34ff2e56b6b9ffdea

See more details on using hashes here.

Provenance

The following attestation bundles were made for bankstatementparser_lsp-0.0.11-py3-none-any.whl:

Publisher: release.yml on sebastienrousseau/bankstatementparser-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page