rustledger-importer
Import framework for rustledger - extract transactions from bank files.
Overview
This crate provides infrastructure for extracting Beancount transactions from
bank statements, credit card statements, and other financial documents. It
follows the design of Python beancount's bean-extract.
Importers come in two flavors:
- Built-in importers (CSV, OFX/QFX) — compiled into the crate.
- WASM importers — third-party
.wasmmodules loaded at runtime through theWasmImporterhost loader. Sandboxed via wasmtime (no FS / network / WASI), so untrusted modules are safe to load. Seeexamples/wasm-importer-csv-examplefor a reference guest implementation built with thewasm_importer_main!macro inrustledger-plugin-types.
Supported Formats
| Format | Source | Description |
|---|---|---|
| CSV | built-in | Configurable CSV importer with column mapping |
| OFX/QFX | built-in | Open Financial Exchange format |
| any | WASM | Any format a third-party .wasm module implements |
Example
use ;
use Path;
// Build the per-call config (CSV in this example).
let config = csv
.account
.currency
.date_column
.narration_column
.amount_column
.build?;
// Dispatch through the registry — `identify()` picks OfxImporter for
// .ofx/.qfx and CsvImporter for .csv. Add WASM importers via
// `register_wasm_from_path` / `register_wasm_dir`; once registered, they
// participate in the same identify-then-extract dispatch.
let registry = with_builtins;
let result = registry.extract?;
for directive in result.directives
Enriched Imports
The enrichment pipeline adds intelligence on top of basic CSV/OFX extraction:
- Auto-inference of CSV format (delimiter, date format, column roles)
- Merchant dictionary for automatic account categorization
- Fingerprinting for dedup against existing ledger entries
- Confidence scores on every enrichment decision
use auto_extract;
use Path;
// Zero-config: auto-detect format and enrich. Signature is
// `(path, account, currency)`.
let result = auto_extract?;
// `EnrichedImportResult.entries: Vec<(Directive, Enrichment)>`.
for in &result.entries
// Or opt-in to enrichment via the builder. `use_merchant_dict` takes a
// bool — pass `true` to enable the built-in merchant dictionary fallback.
use ImporterConfig;
let config = csv
.account
.currency
.use_merchant_dict
.build?;
WASM Importers
Load a third-party importer at runtime from a .wasm file:
use ImporterRegistry;
let mut registry = with_builtins;
// Single-file load (uses default sandbox: 256 MiB memory, 30 s fuel).
let name = registry.register_wasm_from_path?;
println!;
// Or scan a directory — skip-and-collect: one broken module doesn't
// prevent the rest from loading.
let report = registry.register_wasm_dir?;
println!;
for in &report.failures
To author a WASM importer, depend on rustledger-plugin-types with the
guest feature and use the wasm_importer_main! macro. See
examples/wasm-importer-csv-example for a minimal but
realistic implementation and the macro's docs in rustledger-plugin-types.
Key Types
| Type | Description |
|---|---|
Importer |
Trait for file importers — implemented by built-ins and WASM |
ImporterConfig |
Per-call configuration (target account, currency, format-specific) |
ImportResult |
Result containing directives and warnings |
EnrichedImportResult |
Result with (Directive, Enrichment) pairs and warnings |
ImporterRegistry |
Registry; dispatches by identify(); loads WASM importers |
OfxImporter |
Built-in OFX/QFX file importer |
WasmImporter |
Host loader for WASM-implemented importers |
WasmRuntimeConfig |
Per-call sandbox caps (memory, fuel) for WasmImporter |
WasmDirScanReport |
Return type of register_wasm_dir — loaded names + failures |
auto_extract() |
Zero-config import with format auto-detection |
Importer Trait
Implement the Importer trait to add support for new file formats from
inside the workspace. (External authors should target the WASM ABI
instead — wasm_importer_main! in rustledger-plugin-types.)
use ;
use Path;
use Result;
;
License
GPL-3.0