bank-statement-rs
bank-statement-rs is a Rust library for parsing bank and credit card transaction history from multiple common financial export formats.
Features
- Multiple Format Support: QFX/OFX with extensible architecture for CSV and other formats
- Auto-Detection: Automatically detect file format from content and filename
- Builder Pattern: Fluent API for configuring and parsing
- Type-Safe: Strongly-typed transactions with chrono and rust_decimal
- Serde Support: Serialize/deserialize transactions and format configurations
Supported Formats
- ✅ QFX/OFX (both XML 2.x and SGML 1.x formats)
- 🚧 CSV (planned)
- 🚧 OFX (planned - separate from QFX)
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Builder Pattern (Recommended)
The builder pattern provides a fluent and flexible API:
use ParserBuilder;
// Auto-detect format with filename hint
let content = read_to_string?;
let transactions = new
.content
.filename
.parse?;
for tx in transactions
Auto-detect without filename
use ParserBuilder;
let transactions = new
.content
.parse?;
Specify format explicitly
use ;
let transactions = new
.content
.format
.parse?;
API Methods
The ParserBuilder provides the following methods:
.content(&str)- Set the file content to parse.filename(&str)- Set filename for format detection (optional).format(FileFormat)- Explicitly set the format to skip auto-detection (optional).parse()- Parse and returnVec<Transaction>(the default type).parse_into::<T>()- Parse and returnVec<T>whereT: TryFrom<ParsedTransaction>
Architecture
Each parser outputs its raw format-specific structures wrapped in a ParsedTransaction enum:
- QFX/OFX →
ParsedTransaction::Qfx(QfxTransaction) - Future parsers will add their own variants
Default Transaction Structure
The library provides a suggested Transaction struct with TryFrom<ParsedTransaction> implemented:
Custom Output Types
You can create your own transaction structure by implementing TryFrom<ParsedTransaction>:
use ;
// Use parse_into to get your custom type
let my_transactions: = new
.content
.parse_into?;
Extending with Custom Parsers
Implement the Parser trait for your custom format. Each parser should output its own raw format structure:
use Parser;
use ;
// Define your raw format structure
;
// To integrate with the builder, follow these steps:
// 1. Add a variant to ParsedTransaction enum in src/builder.rs:
// ParsedTransaction::Custom(CustomTransaction)
// 2. Add a variant to FileFormat enum in src/builder.rs:
// FileFormat::Custom
// 3. Update FileFormat::parse() to handle the new format
// 4. Update auto-detection logic in ParserBuilder::parse_into()
// 5. Implement TryFrom<CustomTransaction> for Transaction (optional)
See CLAUDE.md for detailed step-by-step instructions on adding new parsers.
Examples
See the examples directory for more usage examples:
# Run with example data
# Parse your own QFX file
License
This project is open source.