With Tabby, a former accountant is using AI to make accountants obsolete
Back to Tutorials
techTutorialbeginner

With Tabby, a former accountant is using AI to make accountants obsolete

September 21, 202644 views5 min read

Learn to build a basic AI-powered bookkeeping assistant that can track financial transactions and provide real-time profit and loss reports, demonstrating core concepts behind tools like Tabby.

Introduction

In this tutorial, you'll learn how to build a basic AI-powered bookkeeping assistant that can process financial data and provide real-time profit and loss reports. This project demonstrates the core concepts behind tools like Tabby that are revolutionizing how accountants work. We'll create a simple command-line application that can track income, expenses, and calculate profit/loss automatically using basic AI techniques.

Prerequisites

  • Basic computer knowledge and ability to run command-line tools
  • Python installed on your computer (version 3.6 or higher)
  • Internet connection for downloading packages
  • Text editor (like VS Code, Sublime Text, or even Notepad)

Step-by-Step Instructions

Step 1: Set Up Your Development Environment

Install Python and Required Packages

First, ensure you have Python installed by opening your terminal or command prompt and typing:

python --version

If Python isn't installed, download it from python.org. Once installed, we'll need to install some packages for our bookkeeping assistant. Open your terminal and run:

pip install pandas numpy

We'll use pandas for data handling and numpy for numerical calculations. These are essential tools for any financial data processing.

Step 2: Create Your Main Application File

Initialize Your Project

Create a new file called bookkeeping_assistant.py in your preferred folder. This will be our main application file. Start by importing the necessary libraries:

import pandas as pd
import numpy as np
import json
from datetime import datetime

This imports the key libraries we'll use: pandas for data management, numpy for calculations, json for data storage, and datetime for handling dates.

Step 3: Create the Data Structure

Define Your Financial Transaction Class

Let's create a basic class to represent financial transactions:

class Transaction:
    def __init__(self, description, amount, category, date=None):
        self.description = description
        self.amount = amount  # Positive for income, negative for expenses
        self.category = category
        self.date = date if date else datetime.now().strftime('%Y-%m-%d')

    def to_dict(self):
        return {
            'description': self.description,
            'amount': self.amount,
            'category': self.category,
            'date': self.date
        }

This class stores transaction details including description, amount (positive for income, negative for expenses), category, and date. The to_dict method helps us easily convert transactions to JSON format for storage.

Step 4: Build the Core Bookkeeping System

Create the Main Bookkeeping Assistant Class

class BookkeepingAssistant:
    def __init__(self):
        self.transactions = []
        self.data_file = 'transactions.json'
        self.load_transactions()

    def add_transaction(self, description, amount, category):
        transaction = Transaction(description, amount, category)
        self.transactions.append(transaction)
        self.save_transactions()
        print(f"Added transaction: {description} - ${amount}")

    def load_transactions(self):
        try:
            with open(self.data_file, 'r') as f:
                data = json.load(f)
                for item in data:
                    transaction = Transaction(item['description'], item['amount'], item['category'], item['date'])
                    self.transactions.append(transaction)
        except FileNotFoundError:
            print("No existing transactions found. Starting fresh.")

    def save_transactions(self):
        data = [t.to_dict() for t in self.transactions]
        with open(self.data_file, 'w') as f:
            json.dump(data, f, indent=2)

This class manages all our transactions. It can add new transactions, load existing ones from a file, and save them. This is the foundation of our bookkeeping system.

Step 5: Add Profit and Loss Calculations

Implement Financial Reporting

    def calculate_profit_loss(self):
        df = pd.DataFrame([t.to_dict() for t in self.transactions])
        if df.empty:
            print("No transactions to analyze.")
            return
        
        total_income = df[df['amount'] > 0]['amount'].sum()
        total_expenses = abs(df[df['amount'] < 0]['amount'].sum())
        net_profit = total_income - total_expenses
        
        print("\n--- Profit and Loss Report ---")
        print(f"Total Income: ${total_income:.2f}")
        print(f"Total Expenses: ${total_expenses:.2f}")
        print(f"Net Profit/Loss: ${net_profit:.2f}")
        
        return {'income': total_income, 'expenses': total_expenses, 'profit': net_profit}

    def get_category_breakdown(self):
        df = pd.DataFrame([t.to_dict() for t in self.transactions])
        if df.empty:
            print("No transactions to analyze.")
            return
        
        category_summary = df.groupby('category')['amount'].sum().sort_values(ascending=False)
        print("\n--- Category Breakdown ---")
        for category, amount in category_summary.items():
            print(f"{category}: ${amount:.2f}")

This code transforms our transaction data into meaningful financial insights. It calculates total income, expenses, and net profit/loss, then breaks down expenses by category. This is what makes AI bookkeeping systems so valuable - they provide instant insights without manual calculation.

Step 6: Create the User Interface

Build the Command-Line Interface

def main():
    assistant = BookkeepingAssistant()
    
    print("Welcome to the AI Bookkeeping Assistant!")
    
    while True:
        print("\nOptions:")
        print("1. Add transaction")
        print("2. View profit/loss")
        print("3. View category breakdown")
        print("4. Exit")
        
        choice = input("\nEnter your choice (1-4): ")
        
        if choice == '1':
            description = input("Enter description: ")
            amount = float(input("Enter amount (positive for income, negative for expense): "))
            category = input("Enter category: ")
            assistant.add_transaction(description, amount, category)
        
        elif choice == '2':
            assistant.calculate_profit_loss()
        
        elif choice == '3':
            assistant.get_category_breakdown()
        
        elif choice == '4':
            print("Thank you for using AI Bookkeeping Assistant!")
            break
        
        else:
            print("Invalid choice. Please try again.")

if __name__ == "__main__":
    main()

This interface allows users to interact with our bookkeeping system. Users can add transactions, view financial reports, and exit the program. It's the user-facing part that makes our AI assistant practical.

Step 7: Test Your Application

Run and Experiment

Save your file and run it in the terminal with:

python bookkeeping_assistant.py

Try adding a few transactions like:

  • Income: "Freelance project" - $500
  • Expense: "Office supplies" - $50
  • Expense: "Software subscription" - $25

Then run the profit/loss report to see your financial summary. This simulates how Tabby processes real-time financial data to give business owners instant insights.

Summary

In this tutorial, you've built a basic AI-powered bookkeeping assistant that can track financial transactions and provide real-time profit and loss reports. While this is a simplified version of what tools like Tabby can do, it demonstrates the core concepts of automated financial data processing. The system uses Python's data handling capabilities to store, analyze, and report on financial information automatically. As you continue developing this project, you could add features like natural language processing for transaction recognition, automated categorization, or integration with accounting software APIs - all of which are being implemented in real AI bookkeeping solutions today.

Related Articles