An augmented SQLAlchemy layer for a pythonic interface to GnuCash SQL documents.
Project description
Project
This project provides a simple interface to a GnuCash Book stored in SQL (sqlite3 or Postgres). It is basically a SQLAlchemy layer augmented with methods to ease the manipulation of core GnuCash objects.
Project is in early development. Knowledge of SQLAlchemy is a probably required…
Installation
From pip:
$ pip install piecash
Usage
The simplest workflow to use piecash is first to open a SQLAlchemy session to a GnuCash Book
import piecash
# open a GnuCash Book
session = piecash.connect_to_gnucash_book("test.gnucash", readonly=True)
Use the SQLAlchemy session to query the Book, for example to query the stock prices
# example 1, print all stock prices in the Book
# display all prices
for price in session.query(piecash.Price).all():
print "{}/{} on {} = {} {}".format(price.commodity.namespace,
price.commodity.mnemonic,
price.date,
float(price.value_num) / price.value_denom,
price.currency.mnemonic,
)
NASDAQ/CZR on 2014-11-12 14:27:00 = 13.65 USD ...
or to query the accounts:
for account in session.query(piecash.Account).all():
print account
Account<> Account<Assets> Account<Assets:Current Assets> Account<Assets:Current Assets:Checking Account> Account<Assets:Current Assets:Savings Account> Account<Assets:Current Assets:Cash in Wallet> Account<Liabilities> Account<Liabilities:Credit Card> Account<Income> Account<Income:Bonus> Account<Income:Gifts Received> ...
Most basic objects used for personal finance are supported (Account, Split, Transaction, Price, …).
A more complete example showing interactions with an existing GnuCash Book created from scratch in GnuCash is available in the tests/ipython subfolder as ipython notebook (ipython session)
To do:
write more tests
implement higher function to offer a higher level API than the SQLAlchemy layer (for instance return a Book instead of SA session, be able to do Book.currencies to return session.query(piecash.Commodity).filter(Commodity.namespace == “CURRENCY”).all())
review non core objects (model_budget, model_business)
write example scripts
improve KVP support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.