OFXParse (version 0.21) is a Python library designed for parsing and working with the Open Financial Exchange (OFX) file format. It extracts data such as transactions, account information, and balance statements from OFX files, making it easier to integrate financial data into applications. The library is actively maintained with a generally stable release cadence.
pip install ofxparseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a simple OFX file. It creates a temporary OFX file, parses it using `OfxParser.parse()`, and then prints out basic account and transaction information. Note the use of `"rb"` (binary read mode) for opening the file.
Always check for attribute existence using `if hasattr(obj, 'attr_name')` or `getattr(obj, 'attr_name', default_value)` before access. For lists (e.g., `accounts`, `transactions`), check if the list is non-empty before indexing.
Ensure you open your `.ofx` files using `open(file_path, "rb")` and pass the binary file handle to `OfxParser.parse()`. If you have OFX content as a string, encode it to bytes first (e.g., `ofx_string.encode('utf-8')`) or save it to a temporary file and open it in binary mode.Inspect the problematic OFX file for XML validity. Sometimes minor manual cleanup (e.g., removing BOM, correcting invalid characters, ensuring proper closing tags) is required before parsing. Consider using `errors='ignore'` with `.decode()` if manually converting to string before `lxml` processing (though binary mode is preferred).
Always open OFX files in binary read mode (`"rb"`) and pass the file handle directly to `OfxParser.parse()`. The library is designed to handle various encodings when given a binary stream.
Verify the content of your OFX file. Ensure it contains actual OFX data and is not zero-bytes. If generating the file, ensure proper content is written. If downloading, try re-downloading the file.
Before accessing `ofx.accounts[0].transactions`, check if `ofx.accounts` exists and if `ofx.accounts[0].transactions` is not empty. Example: `if ofx.accounts and ofx.accounts[0].transactions:`
No dependency data recorded yet.