Skip to main content

FinLang: a deterministic, auditable DSL for financial rules

Project description

FinLang โ€” The Financial Rules Engine

Deterministic. Auditable. Global.
Designed for explainable processing in regulated environments.

PyPI version License: AGPL v3 Build Status Python versions


๐ŸŒ Overview

FinLang is a domain-specific language (DSL) and high-performance CLI engine for financial transaction processing.
It replaces opaque machine-learning categorization with transparent, deterministic rules โ€” delivering explainability, auditability, and global compatibility.

Built for audit-friendly logic and deterministic processing.
A deterministic alternative where explainability and reproducibility matter.


๐Ÿ“ The FinLang DSL

FinLang rules are human-readable, Git-friendly, and designed for precision.
The engine processes rules top-to-bottom; the last matching rule sets the category, while flags accumulate.

# Example: Basic categorization and flagging
rule "GROCERIES: Tesco" {
  match:
    - counterparty ~ "*TESCO*"
  set:
    - category = "Groceries"
    - flags += "Supermarket"
}

# Example: Numeric range and exact match
rule "TRAVEL: High Value Flight" {
  match:
    - counterparty == "BRITISH AIRWAYS"
    - amount in -5000.00 .. -500.00
  set:
    - category = "Travel"
    - flags += "HighValue"
}

โš™๏ธ Key Features (v0.7.7)

Feature Description
Deterministic DSL Human-readable .fin rules language โ€” explainable logic, Git-friendly.
High-Performance Engine Vectorized core (Pandas + NumPy + PyArrow) โ€” 27K+ rows/sec validated throughput.
Dual Backend Standard (Engine: c) or FastIO (Engine: pyarrow) with automatic fallback.
Growth Loop Automated Discover โ†’ Suggest โ†’ Categorize workflow โ€” 97.8% success on addressable patterns.
Global I18n Support US/UK/EU/Commonwealth formats, ยฃ โ‚ฌ $ ยฅ โ‚น stripping, localized decimals/dates/delimiters.
Audit Trail System Every decision logged (before/after state diffs); stateless for reproducibility.
Exclude Marker Boolean exclude column โ€” rule-driven, auditable, supports blacklist/whitelist exception patterns.
CR/DR Semantics Case-insensitive CR/DR (with or without space), accounting negatives (123.45), trailing minus 123.45-.
Amount Synthesis Auto-computes amount = abs(credit) โ€“ abs(debit) across 9 edge cases.
Strict Parsing Locale-aware normalization with configurable thresholds (--strict-parse).
Flag Integrity Append-only (flags +=) with deterministic deduplication.
Integrity Verification Built-in --verify and --verify-full โ€” SHA-256 fingerprinting of immutable fields with optional artifact output.

๐Ÿ“ฆ Installation

Requirements: Python 3.10โ€”3.14

From PyPI (Recommended):

pip install finlang

With Fast I/O (PyArrow):

pip install "finlang[fastio]"

(Enables --fastio for accelerated CSV I/O.)

From Source (Development):

git clone https://github.com/FinLang-Ltd/finlang.git
cd finlang
pip install -e .[fastio]

๐Ÿš€ Quick Start โ€” The 5-Step Growth Loop

1๏ธโƒฃ Initial Categorization

finlang --input transactions.csv --output baseline.csv \
  --rules my_rules.fin --include-pack retail,transport

2๏ธโƒฃ Discover Gaps

finlang-discover --input baseline.csv \
  --candidates candidates.csv --all-candidates all_candidates.csv \
  --min-count 5

3๏ธโƒฃ Suggest Rules (Exact Mode Recommended)

finlang-suggest --input candidates.csv --output suggested_rules.fin \
  --rules my_rules.fin --emit-match exact

4๏ธโƒฃ Merge and Re-run

cat my_rules.fin suggested_rules.fin > merged.fin
finlang --input transactions.csv --output improved.csv \
  --rules merged.fin --include-pack retail,transport

โœ… Expected Result: 5โ€“10% coverage improvement; zero duplicates in exact mode.


๐Ÿ“Š Performance Benchmarks

Measured with --audit-mode none (max throughput).

Dataset Test Rules Time (s) Rows/sec Notes
100 K (UK Synthetic) Growth Loop 121 2.54 39,370 โœ… Baseline
100 K (after Growth Loop) Growth Loop 764 4.96 20,161 โœ… +6.3ร— rules โ†’ โ‰ˆ 2ร— slower
5M ร— 50 cols Benchmark Harness โ€” 187.90 26,600 โœ… High volume validation

v0.7.4 improvement: Cache invalidation fix delivered 3โ€“5% faster runtimes across most data shapes; ~5% integrity test improvement. Headline enterprise throughput: ~27K rows/sec (peak observed: 28.4K).
Cumulative: 10% faster than v0.6.4 (208s โ†’ 188s), +12% throughput.
Audit Overhead: Enabling --audit-mode lite/full reduces throughput by โ‰ˆ38% due to diff calculation; provides full decision provenance.

Note: These figures are validated benchmark results from controlled tests (5M ร— 50 columns). Actual performance varies depending on dataset, ruleset, and audit mode.
See docs/benchmarks.md for details.


๐Ÿ” Cryptographic Integrity Verification (Benchmark)

SHA-256 fingerprint verification benchmarked on large datasets:

Rows Full Validation Engine (FastIO) Result
5M ~5 min 133K rows/s โœ… All fingerprints match
10M ~10 min 156K rows/s โœ… All fingerprints match
20M ~18 min 167K rows/s โœ… All fingerprints match

What this benchmark validated: Every row's immutable fields (date, amount, counterparty) were verified via SHA-256 hash before and after engine processing. Zero cross-row contamination detected. Zero data corruption detected.

Note: As of v0.7.7, SHA-256 integrity verification is available as a CLI feature via --verify (fast fingerprint) and --verify-full (fingerprint + field comparison). Use --verify-output-dir to save audit artifacts (JSON report + proof CSV). See docs/cli_reference.md for details.


๐ŸŒ Internationalization Matrix

Region Example Number Date Order CLI Flags
๐Ÿ‡บ๐Ÿ‡ธ US / ๐Ÿ‡จ๐Ÿ‡ฆ Canada 1,234.56 MM/DD (defaults)
๐Ÿ‡ฌ๐Ÿ‡ง UK / ๐Ÿ‡ฆ๐Ÿ‡บ Commonwealth 1,234.56 DD/MM --dayfirst
๐Ÿ‡ช๐Ÿ‡บ Continental Europe 1.234,56 DD/MM --decimal "," --thousands "." --dayfirst
๐Ÿ‡จ๐Ÿ‡ญ Switzerland 1'234.56 DD/MM --thousands "'" --dayfirst

Auto-Detection and Normalization: BOM-safe UTF-8 encodings, , ; | \t delimiters, and automatic currency symbol stripping.


๐Ÿง  The Growth Loop Explained

Discover โ†’ Suggest โ†’ Categorize โ†’ Repeat

FinLang's Growth Loop accelerates rule creation through data-driven discovery.

  • Discover uncategorized counterparties
  • Suggest new rules in seconds (1:1 mapping in exact mode)
  • Merge + Re-run for incremental coverage gains
  • Validated Result: 97.8% success on addressable patterns
  • ROI: 8.8 transactions categorized per new rule

๐Ÿ“„ See: docs/growth_loop_best_practices.md


๐Ÿงพ Known Limitations (v0.7.x)

  • โš ๏ธ --emit-match fuzzy (default) filters corporate stopwords (LTD, INC, GROUP, etc.) but may still produce broad patterns on short names. โ†’ Use --emit-match exact for production workflows.
  • โš ๏ธ Hyphenated/apostrophe names may affect fuzzy matching (< 1% impact).
  • โš ๏ธ No support for non-Gregorian calendars or non-Western numerals.

๐Ÿ“˜ Documentation

Command-line help:

finlang --help
finlang-discover --help
finlang-suggest --help

๐Ÿงฉ Example CLI Usage

finlang --input bank.csv --output categorized.csv \
  --rules examples/rules.demo.fin \
  --include-pack retail,transport,subs \
  --fastio --audit audit_log.json --audit-mode lite

๐Ÿ“œ License & Commercial Use

FinLang is open source under the GNU Affero General Public License (AGPL-3.0).
Commercial licenses and enterprise support are available via FinLang Ltd.

๐Ÿ“ง info@finlang.io
๐ŸŒ https://finlang.io


Contributing

Contributions are welcome! Before submitting a PR, please review and accept our Contributor Licence Agreement (CLA).


๐Ÿ“Œ Version Summary

Component Version Status
Core Engine v0.7.7 โœ… Production-Ready
CLI Suite v0.7.7 โœ… Validated (118 tests, 9 gates)
Discover/Suggest v0.7.7 โœ… 97.8% accuracy
Integrity Test v0.7.7 โœ… 20M rows verified
Verify v0.7.7 โœ… Built-in --verify / --verify-full
Docs v0.7.7 โœ… Complete
Python Support 3.10โ€”3.14 โœ… Tested

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

finlang-0.7.7.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

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

finlang-0.7.7-py3-none-any.whl (69.5 kB view details)

Uploaded Python 3

File details

Details for the file finlang-0.7.7.tar.gz.

File metadata

  • Download URL: finlang-0.7.7.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for finlang-0.7.7.tar.gz
Algorithm Hash digest
SHA256 899f5ece07454d6d5cf8c45fad520ed5059592aa28625135d61b991f11488701
MD5 8551fe9e14c9f2b66eabeb6b31b4abd5
BLAKE2b-256 2c1468c47e33d89ec102cf9b73e897fd3abe22ed72ac16c609cdf708366ed813

See more details on using hashes here.

File details

Details for the file finlang-0.7.7-py3-none-any.whl.

File metadata

  • Download URL: finlang-0.7.7-py3-none-any.whl
  • Upload date:
  • Size: 69.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for finlang-0.7.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ce097ec4f7f5c72b3cf24234419228b21a4b44fff166656ef762708615df6db7
MD5 c655f57f886521f94562c81c741057db
BLAKE2b-256 1fdc60a576050589c6e736b4e85e89ba436c745ea99744de932dd96fed306a30

See more details on using hashes here.

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