Giter Site home page Giter Site logo

gnucashxml's Introduction

GNU Cash XML Library

gnucashxml is a Python library to parse GNU Cash XML files. This allows writing reporting utilities that do not rely on the GNU Cash libraries themselves, or require the main program to run at all. Tested with GNU Cash 2.4.10.

The library supports extracting the account tree, including all transactions and splits. It does not support scheduled transactions, price tables, and likely none but the most basic commodities. In particular, writing of XML files is not supported.

Usage

The interface is intended to allow quickly writing reports using Python. It reuses as many Python data structures as possible. Whenever dates or times are used, the standard library datetime is used. All account and transaction balances are represented as the standard Decimal type.

The three main concepts in GNU Cash are accounts, transactions, and splits. A transaction consists of a number of splits that specify from which account or to which account commodities are transferred by this transaction. All splits within a transaction together are balanced.

The main classes provided by gnucashxml mirror these concepts. A Book is the main class containing everything else. A Commodity is what is stored in an account, for example, Euros or Dollars. An Account is part of a tree structure and contains splits. Splits again are part of Transactions.

These classes all have a slots member, which is a simple dictionary for extra information. GNU Cash information such as "hidden" are recorded here.

Example

import gnucashxml

book = gnucashxml.from_filename("test.gnucash")

income_total = 0
expense_total = 0
for account, subaccounts, splits in book.walk():
    if account.actype == 'INCOME':
        income_total += sum(split.value for split in account.splits)
    elif account.actype == 'EXPENSE':
        expense_total += sum(split.value for split in account.splits)

print "Total income : {:9.2f}".format(income_total * -1)
print "Total expense: {:9.2f}".format(expense_total)

gnucashxml's People

Contributors

jorgenschaefer avatar seands avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.