reports in Python
mark at parit.ca
Fri Jul 30 13:54:42 EDT 2010
> The question is how much infrastructure is provided by python-bindings
> and what is missing so that Gnucash can have nice customization
> features via python & some templating language?
Sorry for taking awhile to get back on this.
I'm not sure what is missing, as I'm been happy with what's available
for the reports I wanted to write to date. (see some examples of reports
and other uses of the python bindings in
The intent with the python bindings was to expose the C api to python
programmers writing python programs that run outside of GnuCash, not
python programs embedded in GnuCash, which is a lot harder to do.
Perhaps someone will be so brave some day.
If there is some aspect of the C api that isn't currently exposed that
people would like exposed because it would make it easier to write
(external) reports in python, someone should post a feature request to
Bugzilla naming the specific .h files, functions that should be made
I suspect GnuCash's guile based reports also have a common library of
scheme code that this shared amongst the guile reports; and that the
guile based reports use a mix of the C api and this GnuCash-guile-report
api. I don't think it would be a good idea to try and expose this
additional scheme code to python; as that would be some pretty messy
bindings work to jump from python to C to scheme.
Nor do I think it would be a good idea to immediately try and clone the
things that go on in the GnuCash scheme report infrastructure. Python is
a fairly capable language in its own right, so I'd suggest that folks
try writing the reports of their dreams using just python, third party
python libraries, and the python bindings and see how far they can get.
Python comes with a fairly large standard library, and some parts of it
can definitely aid in reporting writing; for example, some of the
reports I have written have used CSV and a output format and I took
advantage of the csv module in python to do so. I think there may also
be built-in modules in python that help with html and XML output.
There is a pretty big and accessible universe of python libraries that
could be combined with the python bindings to aid in writing and
outputting reports. I would include in that templating engines, and not
only third party ones, but there are a few templating and string
formatting things built-in to python as well. As an example, I've
attached some example code showing a simple html table report made with
Once a body of gnucash python reports start to be written by people,
we'll be able to see if people are repeating themselves and the work of
others over and over, and then we'll know what kinds of things need to
be located in a python gnucash reports module
>>> from gnucash.reports import blah
> p.s. Maybe there could be interest for some bounty or to fund this
> development which would certainly make Gnucashe much more appealing to
> wider audience?
To alter that suggestion to what I'm saying: direct a bounty towards a
specific kind of report being authored in python, which will then be
useful in its own right, and will be a useful example that can be
studied to see if the combination of python, third party python modules,
and the gnucash python bindings can do the job elegantly without any
further library development.
I would consider bidding if such a bounty were offered, and the bounty
value wouldn't need to be as high if the particular report can be done
with all report code writing and not new library development.
> I'm curious what would be required to tweak Gnucash reports externally
> using your bindings and some (standard) Python templating language?
Typical report overview: Use the python bindings and python structure
statements (if, for, etc..) to step through the accounts, splits, and
transactions of interest, use python data structures (list, dict, set,
etc..) to structure/index/store what has been gathered in a way
appropriate to the report, and use some kind of output format (plain
text, txt, html, csv) to present that retrieved information.
I think that's more or less how things are done in the report
ParIT Worker Co-op
cc fellow ParIT members
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 639 bytes
Desc: not available
More information about the gnucash-devel