Start Accounting in Python

A great field with a great programming language

Timo Kats
Analytics Vidhya
4 min readApr 25, 2021

--

Photo by Claudio Schwarz | @purzlbaum on Unsplash

NOTE: This article is outdated since a newer version of fibooks has been released. Please go to my new article on fibooks for a tutorial on the latest version.

Introduction

Python is big in finance. Nowadays the originally Dutch programming language is the go-to tool for many important tasks like; algorithmic trading, data analytics and crypto. One of the biggest reasons Python is this successful is due to the amount of libraries that the language offers. Hence it seems as if for every important task in finance there’s a Python library available.

However, for accounting (and financial statement analysis in general) Python never quite managed to break through. That’s why most accountants still use excel or other similar programs to do their bookkeeping. Needless to say, these programs are not as scalable and versatile as a programming language.

That’s why in this article we’ll explore a new Python library that manages to fill that gap, called “fibooks”. This library currently has 3 of the 4 main financial statements and offers a large set of built in computations that can help anyone getting more insight in a company’s financial performance.

Getting started

Fibooks can be installed in terminal through the Python package installer, also known as “pip”. If you use PyCharm (or any other IDE) then please check the installation guidelines for that environment. Do keep in mind that regardless of your environment this package is optimized for Python 3.

pip install fibooks

When the download has been completed you can check if your installation has been successful with the following code snippet. If the code below outputs the current version number (at this moment 1.0.3) then you’re good to go!

>>> from fibooks import info
>>> info.get_version()

Loading data

The first step in financial statement analysis would be to get the actual reports loaded into a statement. For this example we’ll use a balance sheet to do this. To import the functionalities from the balance sheet you can use the following command.

>>> from fibooks import balance_sheet

After you’ve imported the balance sheet you can declare it and read data into it. Fibooks offers many ways to create and import data but for this example we’ll import a json file. If you want to continue experimenting with this file after reading this article then you can find it here.

>>> my_company = balance_sheet('my company in 2020')
>>> my_company.import_json('balance_sheet.json')
>>> my_company.make()

What’s very important to note is that you need to call the function “make” in order to actually load the data. If this step is left out fibooks won’t load any data, even if it’s already imported through another function.

Exploring the data

Now that the data is loaded successfully we can explore it. In fibooks there are many ways to do this. The first (and most simple) way would be to just print the balance sheet to the standard output. To do this call the function “print”.

>>> my_company.print()
The balance sheet of: my company in 2020
assets
current assets
cash 10
long-term assets
buildings 40
___+
total assets 50
liabilities
current liabilities
accounts payable 5
long-term liabilities
debt 15
___+
total liabilities 20
equity
stonks! 30
___+
total equity 30

Additionally, it’s also possible to export the balance sheet to a file. If you want to save your balance sheet you can export it to json format, if you want to look at your balance sheet you can export it to text or excel format. The last one does require excel to be installed on your computer, if this requirement is satisfied just call the “export_excel” function along with the filename. This would result in the following spreadsheet.

screenshot of the excel file fibooks made

When looking at the balance sheet in this excel format it’s quite easy to see that the balance sheet identity (assets = liabilities + equity) is being upheld. What’s also visible in this spreadsheet is that there’s seemingly not that much cash. In order to conclude whether this suspicion is actually justified we can use the compute class.

Making computations

In order to make computations with fibooks it’s required to import the compute class. This class does not have to be initiated.

>>> from fibooks import compute

A good ratio that checks whether a company has enough cash in stock would be the “current ratio”. This ratio divides the current assets by the current liabilities, which shows how much of the company’s short term debt it can pay off with its short term assets. In fibooks this is especially easy to do since the ratio is built into the class and it only needs a balance sheet as input.

>>> current_ratio = compute.current_ratio(my_company)
>>> print(current_ratio)
2.0

According to the computation we just made the current ratio equals 2. This means that our suspicion has been proven wrong and the company has more than enough cash in the bank.

In conclusion

What this article hopefully shows is how Python can be used for financial statement analysis and how simple it can be, because through using libraries like fibooks one does not need much programming experience nor expensive software to get started in the field of accounting.

--

--