{"library":"ofxparse","title":"OFXParse","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install ofxparse"],"cli":null},"imports":["from ofxparse import OfxParser"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom ofxparse import OfxParser\n\n# Create a dummy OFX file for demonstration\nofx_content_simple = \"\"\"\nOFXHEADER:100\nDATA:OFXSGML\nAOFX:V1\n<OFX>\n    <BANKMSGSRQV1>\n        <STMTTRNRS>\n            <TRNUID>0</TRNUID>\n            <STATUS><CODE>0</CODE><SEVERITY>INFO</SEVERITY></STATUS>\n            <STMTRS>\n                <CURDEF>USD</CURDEF>\n                <BANKACCTFROM>\n                    <BANKID>123456789</BANKID>\n                    <ACCTID>0000000000</ACCTID>\n                    <ACCTTYPE>CHECKING</ACCTTYPE>\n                </BANKACCTFROM>\n                <BANKTRANLIST>\n                    <DTSTART>20230101000000</DTSTART>\n                    <DTEND>20230131000000</DTEND>\n                    <STMTTRN>\n                        <TRNTYPE>DEBIT</TRNTYPE>\n                        <DTPOSTED>20230105000000</DTPOSTED>\n                        <TRNAMT>-50.00</TRNAMT>\n                        <FITID>12345</FITID>\n                        <NAME>Grocery Store</NAME>\n                        <MEMO>Weekly groceries</MEMO>\n                    </STMTTRN>\n                    <STMTTRN>\n                        <TRNTYPE>CREDIT</TRNTYPE>\n                        <DTPOSTED>20230110000000</DTPOSTED>\n                        <TRNAMT>1000.00</TRNAMT>\n                        <FITID>67890</FITID>\n                        <NAME>Payroll</NAME>\n                        <MEMO>Monthly salary</MEMO>\n                    </STMTTRN>\n                </BANKTRANLIST>\n                <LEDGERBAL>\n                    <BALAMT>1500.00</BALAMT>\n                    <DTASOF>20230131000000</DTASOF>\n                </LEDGERBAL>\n            </STMTRS>\n        </STMTTRNRS>\n    </BANKMSGSRQV1>\n</OFX>\n    \"\"\"\n    \nfile_path = \"example.ofx\"\nwith open(file_path, \"w\", encoding=\"utf-8\") as f:\n    f.write(ofx_content_simple)\n\ntry:\n    # Always open OFX files in binary read mode ('rb')\n    with open(file_path, \"rb\") as f:\n        ofx = OfxParser.parse(f)\n\n    if ofx.accounts:\n        account = ofx.accounts[0]\n        print(f\"Bank ID: {account.bank_id}\")\n        print(f\"Account ID: {account.account_id}\")\n        print(f\"Account Type: {account.account_type}\")\n        \n        if account.transactions:\n            print(\"\\nTransactions:\")\n            for transaction in account.transactions:\n                print(f\"  Date: {transaction.date.strftime('%Y-%m-%d')}, Amount: {transaction.amount}, Description: {getattr(transaction, 'memo', 'N/A')}\")\n        else:\n            print(\"\\nNo transactions found.\")\n\n        if account.ledger_balance:\n            print(f\"\\nLedger Balance: {account.ledger_balance}\")\n        else:\n            print(\"\\nNo ledger balance found.\")\n    else:\n        print(\"No accounts found in OFX file.\")\n\nexcept Exception as e:\n    print(f\"Error parsing OFX: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(file_path):\n        os.remove(file_path)\n","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}