Python bindings: patch, documentation, examples

Marc Shapiro marcnshap at
Sat May 10 02:06:11 EDT 2014

On 05/09/2014 06:37 PM, David Osguthorpe wrote:
> On Thu, May 08, 2014 at 11:47:34PM -0700, mshapiro wrote:
>> David Osguthorpe wrote
>>> I have a very hacky implementation in gnucash to call python from guile
>>> and
>>> return results to guile - I found existing libraries to do both
>>> (no updates to gnucash required - just a user prototype.scm file)
>> Can you post what libraries you used, where you got them, how to use them
>> and your prototype.scm file.  Also, any pointers to useful documentation for
>> using the Python bindings would be greatly appreciated.  I am primarily
>> interested (at the moment) in accessing budgeting information and future
>> transactions, as well as accounts, since I would like to do more forecasting
>> than the standard reports provide.
> it is really hacky - and I still had crashes when attempting to create real reports
> so its very, very alpha
> but if you wish to pursue it here are the details
I have the feeling that I will be better off to just write a standalone 
python script.  This is not really a problem.  A program to do 
forecasting can be done outside gnucash just fine.  Except that I still 
need to find a way to access the future transactions and the budget 
information.  I haven't seen either of these in any of the example 
reports for the python bindings.  Does anyone know of any info on how to 
use the python bindings to access these?
> note this does not use any of the python bindings - as far as I can tell they only work for
> non-gui standalone scripts - well its the only Ive used them
> - you would write a script to access your gnucash database (xml or SQL) and use any python
> modules to format the data for a new report completely outside of gnucash
> for the moment I would say you would be better just writing command line scripts
> using the python bindings to generate HTML or whatever reports
> here are some details
> 1. you need pyguile - a module for calling guile version of scheme from python
> - unfortunately the available source has not been udpated for years so needed quite
> a bit of patching to build (I run under macports on OSX mainly)
> - one patch I did have to add was the ability to return so called SCM (scheme) objects
> back to guile
> 2. you need schemepy - which has a module for calling python from guile version of scheme
> - again the available source has not been udpated for years so needed
> some patching to get running
> Then you have the prototype.scm (simply not bothered to change name) which sets up
> to call python where you could write your report.
> My initial goal was to write reports in python - Im primarily writing in this now
> and although I had tried scheme for a multiple stock price scatter plot report every time I went
> back trying to re-think in scheme was a pain
I tried to write my report in scheme, and I can't really say that I 
failed.  Just that I never got it finished.  I took the Balance Sheet , 
the Budget Report and the Future Transactions Report and tried to put 
them together.  I was able to successfully combine all of the required 
options so that they can be input on a singe screen.  Then it simply 
runs the Balance Sheet.  If I could figure out how to access the future 
transactions and budgeting data and update the accounts on the Balance 
Sheet before displaying them then I would be all set.  But, so far, I 
have not been able to wrap my head around that much scheme.  As a 
co-worker says of LISP (he uses it in AutoCad) I find myself Lost In 
Stupid Parenthesis.  It makes my head hurt.
> The major problem I ran across is that when analysing the GUI report system in gnucash
> I discovered it was not done in pure gtk but some of the gui is actually written in scheme
> by calling gtk gunctions via swig wrapped functions involving gtk
> - to directly call python reports would need re-writing most of this GUI scheme stuff using
> the python gtk library - not difficult but seemed like a lot of work
> I had hoped to find a report function where I could plugin in a call to python so could then
> do the report in python (python has the ctypes module which allows calling C functions
> in  arbitrary C shared libraries such as gnucash uses) - pygtk allows direct use of gtk functions
> in python
> I did this around 2.4.7 and am looking to review it now at 2.6.3
> from that analysis as far as I could tell the final report result is an html text string which is
> written to a file - again these components using scheme coding
> If you really want the files let me know
Yes.  If you can post the files, or links to them, then I will have them 
if I decide to try and go down that route.  If not, well, it won't hurt 
to have them and maybe it can help someone else.
> as you have discovered there isnt much documentation of the python bindings
Yes.  If I had proper documentation then I would have just written the 
standalone report and been done with it.  As it stands, I have no actual 
proof that the bindings will give me access to the budgeting and future 
transactions.  That may never have been included in them, but since no 
one actually seems to have documented what is, or is not, included (let 
alone how to use it) it makes it kind of difficult.


More information about the gnucash-devel mailing list