GnuCash  5.6-150-g038405b370+
simple_book.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 
6 
7 import sys
8 from gnucash import Session, SessionOpenMode
9 
10 # We need to tell GnuCash the data format to create the new file as (xml://)
11 uri = "xml:///tmp/simple_book.gnucash"
12 
13 print("uri:", uri)
14 with Session(uri, SessionOpenMode.SESSION_NEW_STORE) as ses:
15  book = ses.get_book()
16 
17  #Call some methods that produce output to show that Book works
18  book.get_root_account().SetDescription("hello, book")
19  print("Book is saved:", not book.session_not_saved())
20 
21  #As long as there's no exceptions, book is automatically saved
22  #when session ends.
23  print("saving...")
24 
25 print("Book is saved:", not book.session_not_saved())