expensor

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2026 License: AGPL-3.0

README

expensor

Expensor is a utility to find expense related emails from my bank and add those expenses to a Google Sheet for expense tracking. The Google Sheet then feeds a Grafana dashboard. Expensor relies on config based rules which can work for almost everyone.

I've documented why exactly expensor works for me on my blog. If you find these reasons just, you might find it useful too. The rules are dead simple regex extractions which are fast (as far as reading emails go) and can be updated/modified pretty easily.

How does it work?

Expensor is designed to

  1. Periodically check my inbox
  2. Run the queries defined in my rules to find emails of interest
  3. Extract transaction details like the amount, merchant name, date of transaction.
  4. Write them to a Google Sheet.
  5. Repeat

Installation

Pre-built Binaries

Download the latest release for your platform from the releases page.

Docker

Pull the latest Docker image from GitHub Container Registry:

docker pull ghcr.io/arionmiles/expensor:latest
From Source

Requires Go 1.25.5 or later:

go install github.com/ArionMiles/expensor/cmd/expensor@latest

Setup

  1. Configure Google Cloud Project

    • Follow the Gmail API Quickstart Guide
    • Download the OAuth credentials JSON file
    • Enable both Gmail API and Google Sheets API for your project
  2. Place Credentials File Save your OAuth credentials JSON file to:

    data/client_secret.json
    
  3. Run Setup

    expensor setup
    

    This will guide you through OAuth authentication and save the token to data/token.json.

  4. Set Environment Variables

    # Required: Sheet name/tab within the spreadsheet
    export GSHEETS_NAME="Sheet1"
    
    # One of these is required:
    export GSHEETS_ID="your-existing-spreadsheet-id"  # Use existing sheet
    # OR
    export GSHEETS_TITLE="Expense Report"  # Create new sheet with this title
    
  5. Run Expensor

    expensor run
    

Running with Docker

Create a docker-compose.yml file:

version: '3.8'
services:
  expensor:
    image: ghcr.io/arionmiles/expensor:latest
    environment:
      - GSHEETS_ID=${GSHEETS_ID}
      - GSHEETS_NAME=${GSHEETS_NAME}
    volumes:
      - ./data:/app/data  # Mount data directory for credentials and token
    restart: unless-stopped

Create a .env file with your configuration:

GSHEETS_ID=your-spreadsheet-id
GSHEETS_NAME=Sheet1

Place your files in the data/ directory:

  • data/client_secret.json - Your Google OAuth credentials
  • data/token.json - OAuth token (generated by running expensor setup)

Run with:

docker-compose up -d

Important: You must run expensor setup once (either locally or in the container) to generate the OAuth token before the app will work.

Configuration

Required Files
File Description
data/client_secret.json Google OAuth credentials (download from Google Cloud Console)
data/token.json OAuth token (auto-generated by expensor setup)
Environment Variables
Variable Required Description
GSHEETS_NAME Yes Name of the sheet/tab within the spreadsheet
GSHEETS_ID One of ID/Title ID of an existing Google Spreadsheet
GSHEETS_TITLE One of ID/Title Title for creating a new Google Spreadsheet
LOG_LEVEL No Logging level: DEBUG, INFO (default), WARN, ERROR

Development

This project uses Task for automation.

Setup Development Environment
# Install Task (if not already installed)
brew install go-task/tap/go-task  # macOS
# or
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin

# Install development tools
task install-tools
Common Tasks
# Format code
task fmt

# Run linter (local config)
task lint

# Run tests
task test

# Run tests with coverage
task test:cover

# Build binary
task build:binary

# Build Docker image
task build:docker

# Run all CI checks
task ci

Expensor doesn't support/recognize transactions from my bank

Open an issue with the email body content and I will take a look, and possibly add the rules into expensor so those are supported.

Directories

Path Synopsis
cmd
emaildump command
Command emaildump fetches emails matching rules and dumps their bodies to files.
Command emaildump fetches emails matching rules and dumps their bodies to files.
expensor command
pkg
api
Package api defines the core interfaces and data structures for expensor.
Package api defines the core interfaces and data structures for expensor.
client
Package client provides OAuth2 client setup for Google APIs.
Package client provides OAuth2 client setup for Google APIs.
logging
Package logging provides structured logging configuration using log/slog.
Package logging provides structured logging configuration using log/slog.
reader/gmail
Package gmail implements a Reader that extracts transactions from Gmail.
Package gmail implements a Reader that extracts transactions from Gmail.
writer/buffered
Package buffered provides a buffered writer base for batch writes.
Package buffered provides a buffered writer base for batch writes.
writer/csv
Package csv implements a Writer that writes transactions to a CSV file.
Package csv implements a Writer that writes transactions to a CSV file.
writer/json
Package json implements a Writer that writes transactions to a JSON file.
Package json implements a Writer that writes transactions to a JSON file.
writer/sheets
Package sheets implements a Writer that writes transactions to Google Sheets.
Package sheets implements a Writer that writes transactions to Google Sheets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL