Package: gnucashreport
Python library for get reports fromGnuCashto xlsx files.It connects directly to the GnuCash book (xml or sql) andPandasuse to building reports.
No cycles for calculation, less errors, less code.The library is cross-platform, Excel is not required, you can use LibreOffice/OpenOfficeGnuCash python bindings not use, because it platform depended and unstable.
All data from GnuCash loads into DataFrames as is, table to table. Then data are processed only thru Pandas.InstallInstallPythonversion 3 (version 2 should work, but I have not tested)Install gnucashreport:pip install gnucashreportNow, you may use cli tool gcreport[1]Pandas need install before, because numpy haveinstallation thru install_requires directive issueSimple command line toolLibrary contain the simple cli tool, usage:gcreport gnucash_file xlsx_file [--glevel glevel] [--open_if_lock]gnucash_fileYour gnucash database filexlsx_filePath to xlsx file for saving reports--glevelglevelLevel to group accounts, may be multiple (–glevel 0 –glevel 1)--open_if_lockOpen sqlite base even if opened other userIt’s save all reports to excel file. (As all_reports_excel function)Examples>>> import gnucashreport
>>> gcrep = GCReport()open gnucash book (sql or xml)>>> gcrep.open_book_file('v:/gnucash-base/sqlite/GnuCash-base.gnucash', open_if_lock=True)save all splits to Excel (with account name, decription, currency mnemonic and other)>>> from gnucashreport.utils import dataframe_to_excel
>>> dataframe_to_excel(gcrep.df_splits, 'v:/tables/splits.xlsx')Save complex reports in xlsx file:This report contain:Income, expense, profit, assets, loans, equity by months each year (sheet on each year)Income, expense, profit, assets, loans, equity by years on each full yearPersonal inflation (annual expenditure growth)Return on assetsSome charts>>> gcrep.all_reports_excel('v:/tables/ex-test.xlsx', glevel=1)Return on assetsThis option is experimental. A few tests written. But it looks like the truth :)The library may consider the profitability of accounts taking into account the hierarchy.
Any asset accounts: deposit, liability, bank, not only stock. You can calculate the yield for all time or a specified period.
You can calculate the portfolio return of the stock or all of the assets.You should mark the account of incomes and expenses for calculation of yield.
Set%invest%in notes of account. Then the account and its descendants will be taken into when calculating profitability.
If you mark the account%no_invest%in notes, it and its descendants will not be considered in calculating the yield# open gnucash bookimportgnucashreportgcrep=GCReport()gcrep.open_book_file(your_gnucash_file)# Get return on assetsgcrep.returns_report_excel('returns.xlsx')See the sheet ‘return’ in .xlsx file after launch command line toolAll results are displayed in percent per annum:TotalThe total return on asset taking into account the costsMoney flowProfitability money flow from account. Dividends, interests on other account, etcExpenseThe costs of servicing the account (per annum)CapitalCapital gainsExplain glevelglevel - how group accounts by levels: array of levels or single int levelExamples:Accounts structure:account levels012Assets:Current assets:CashAssets:Current assets:CardAssets:Reserve:DepositeAssets:Reserve:CashExample 1:glevel=[0, 1]Group accounts for 0 and 1 level, into 2 rows and 2 columns (Multiindex dataframe):01AssetsCurrent assetsReserveExample 2:glevel=1Groups only 1 level, into 2 rows and 1 column:1Current assetsReserveTestingAll my testing data is real. Then all testing function use external folder.
For create test data, save sql book file and xml book file into any folder. Use the same data for sql and xml.
Create empty folder for test data.
Set this options in src/test/basetest.pybookfile_sql=your_sql_basebookfile_xml=your_xml_basedir_testdata=folder_for_test_dataRun the script src/test/savetestdata.py. Run only on working commit version!Now you may run tests.setup.py testProfitability test use special GnuCash book file in test/data/xirr-test.gnucashlicenseGNU GPL 3authorPartizand