Difference between revisions of "Python Bindings"

From GnuCash
Jump to: navigation, search
(Setting things up)
(Setting things up)
Line 6: Line 6:
  
 
= Setting things up =
 
= Setting things up =
 
+
== Linux ==
 
I use ipython for an interactive shell.  If you prefer something else, let us know if there is any difference.
 
I use ipython for an interactive shell.  If you prefer something else, let us know if there is any difference.
  
Line 12: Line 12:
  
 
This adds the gnucash python bindings to your PYTHONPATH assuming that your gnucash resides in /export/gnucash.   
 
This adds the gnucash python bindings to your PYTHONPATH assuming that your gnucash resides in /export/gnucash.   
 
Note: if you compiled gnucash from macports, your path may be as follows:
 
 
  /opt/local/lib/python2.7/site-packages
 
  
 
You can then either start up an interactive python session with ipython or call your script to be executed.
 
You can then either start up an interactive python session with ipython or call your script to be executed.
  
 
  gnucash-env ipython
 
  gnucash-env ipython
  gnucash-env python $scriptyouwanttorun
+
  gnucash-env python /path/to/script
  
 
Note: to install ipython run
 
Note: to install ipython run
 +
  sudo easy_install ipython
  
   sudo easy_install ipython
+
== Mac OSX ==
 +
 
 +
Install GnuCash via macports[http://wiki.gnucash.org/wiki/MacOSX/MacPortsDetail#Using_MacPorts_to_install_a_recent_stable_release_of_GnuCash]
 +
   sudo port install gnucash +python27
 +
 
 +
Note: at the time of writing, only the non-quartz environment is supported.
 +
 
 +
Setup the PYTHONPATH to point to your macports install
 +
  export PYTHONPATH=$PYTHONPATH:/opt/local/lib/python2.7/site-packages
  
Note: if you get errors when using the interactive shell with
+
You can then either start up an interactive python session with ipython or call your script to be executed.
  gnucash-env ipython
 
try
 
 
   ipython
 
   ipython
instead
+
  python /path/to/script
  
 
= Documentation =
 
= Documentation =

Revision as of 12:38, 18 July 2012

Python bindings have been recently added to gnucash. There is still very little documentation and probably few people would know how to use it. While not a manual, this page was created in the hope to provide information for those interested in gnucash and python.

See also

Setting things up

Linux

I use ipython for an interactive shell. If you prefer something else, let us know if there is any difference.

export PYTHONPATH=$PYTHONPATH:/export/gnucash/lib/python2.7/site-packages

This adds the gnucash python bindings to your PYTHONPATH assuming that your gnucash resides in /export/gnucash.

You can then either start up an interactive python session with ipython or call your script to be executed.

gnucash-env ipython
gnucash-env python /path/to/script

Note: to install ipython run

 sudo easy_install ipython

Mac OSX

Install GnuCash via macports[1]

 sudo port install gnucash +python27

Note: at the time of writing, only the non-quartz environment is supported.

Setup the PYTHONPATH to point to your macports install

 export PYTHONPATH=$PYTHONPATH:/opt/local/lib/python2.7/site-packages 

You can then either start up an interactive python session with ipython or call your script to be executed.

 ipython
 python /path/to/script

Documentation

As pointed out in the introductory paragraph, the documentation is rather slim at this point in time. Here are some sources where you might be able to find what you are looking for. Generally speaking, this is not yet end-user friendly stuff.

  • Have a look at the page python-bindings in doxygen source-documentation
  • example scripts from the source code and in doxygen
  • business functions documentation
  • inside ipython
    • big long list of stuff
      • import gnucash.gnucash_core_c
      • help(gnucash.gnucash_core_c)
      • dir(gnucash.gnucash_core_c)
    • higher abstraction level help
      • import gnucash.gnucash_core
      • import gnucash.gnucash_business
      • help(gnucash.gnucash_core)
      • help(gnucash.gnucash_business)

Again, http://article.gmane.org/gmane.comp.gnome.apps.gnucash.devel/23613 contains some more hopefully useful pointers.