Skip to content

Add professional financial statement formatter to finquick #76

@dckc

Description

@dckc

Problem

Financial data from GnuCash SQLite databases often needs to be presented in a professional, readable format with proper currency symbols, thousands separators, and column alignment. Currently, raw SQL output is difficult to read and share.

Proposed Solution

Add a new package packages/format-financial/ with a Python script that formats financial data tables with:

Key Features

  • Currency formatting: Automatic $ symbols and thousands separators ($1,234.56)
  • Perfect column alignment: Dynamic width calculation for clean tables
  • Dual output modes: Both plain text (terminal-friendly) and markdown table formats
  • Decimal precision: Uses Python's Decimal class to avoid floating-point errors
  • Testable design: I/O separated from formatting logic with comprehensive doctests

Usage Examples

# Plain text output (also valid markdown)
python3 format_financial.py database.sqlite view_name

# Pure markdown output  
python3 format_financial.py database.sqlite view_name --markdown

Sample Output

| as_of_date |      assets | liabilities |   net_worth | retained_earnings |      equity |    eq |
| ---------: | ----------: | ----------: | ----------: | ----------------: | ----------: | ----: |
| 2024-12-31 | $796,380.82 |       $0.00 | $796,380.82 |        $25,222.54 | $771,158.28 | $0.00 |
| 2025-06-30 | $811,111.21 |       $0.00 | $811,111.21 |        $36,153.82 | $774,957.39 | $0.00 |

Technical Implementation

  • Object capability discipline: SQLite connections and stdout injected for testability
  • Comprehensive doctests: All formatting functions have embedded tests
  • Clean separation: I/O code isolated in _script_io() function
  • Robust error handling: Graceful fallbacks for edge cases

Benefits

  • Professional financial reports suitable for sharing
  • Works with any SQLite view/table containing financial data
  • Eliminates manual formatting of GnuCash query results
  • Reusable across different finquick workflows
  • Well-tested and maintainable code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions