Python API, book options - GObject, QofInstance etc.

Christoph Holtermann c.holtermann at
Sun Jun 22 07:38:24 EDT 2014

Am 21.06.2014 00:10, schrieb John Ralls:
> On Jun 20, 2014, at 2:23 PM, Christoph Holtermann <c.holtermann at> wrote:
>> Hello,
>> I had just the same question for a while. I have been successful to access
>> that data. I had to make some modifications which I put in a branch on
>> github:
>> See thread "Working example of kvp acess in Python".
>> But the best way to access that data has yet to be found before I ask it
>> to be pulled into master.
> KVP is private to the engine and off limits for python bindings. We’re certainly not going to revert the private-kvp changes, which is what your fork partly does.
> In master, all of the stuff stored in KVP is accessible via GObject properties. QofInstance seems not to be exported, but you can import GObject via gobject-introspection and use GObject.GObject.get/set_property(); if you write just be sure to do it in an edit/commit block and to mark the instance dirty.
Thanks for pointing this way. I'll have a look at it. I guess using Python I'll need something like PyGObject to do that. ( I found GObject via
>> from gi.repository import GObject

but the c/c++ object hierarchy sems not yet to be accessible in Python. So to be able to use  GObject.GObject.get/set_property()
There would need to be a relation of that kind between the book/Transaction/whatever object and GObject.

This leads to the question of type casting macros (is that the right name ?):
In the sources there is the makro QOF_INSTANCE which is widely used. I did not see a way to access it with python so I wrote
QofInstance *qof_book_get_qof_instance (QofBook *book) {
     return (QOF_INSTANCE (book));
in src/optional/python-bindings/gnucash_core.i

which gives me access to QofInstance in Python.

1) Is it legitimate to access (the books) QofInstance from Python ?
2) Is there a better way for type casting ?

QofInstance on the other hand seems to be a descendant of GObject. Objects are being treated as GObject, Transaction (etc.), QofInstance.
Is this varying access also useful to be accessed via python ?

(How) Can I access a book, a transaction, etc. as GObject in Python ?

I'm happy just to go the main road. No need to establish ways that diverge from the intended API. I just need to get the intention.

Just to get things right about KVP:
1) It's not intended to change KVPs from Python. So there should be no representation of class KVPFrame. ?

Sorry for that bunch of questions.

> Regards,
> John Ralls


Christoph Holtermann

--- Nachricht gesendet von C. Holtermann ---
-                                          -
-  Verschlüsselte Nachrichten können über  -
- den öffentlichen Schlüssel auf folgendem -
- Keyserver an mich gesendet werden:       -

More information about the gnucash-devel mailing list