Would you like to be able to analyze your financial data in Mint using your own dashboards and data tools? Mint is a popular finance application that offers free budget tracking, investment monitoring, bill payment, and more. However, at the time of this article, it still lacks an official API.
As someone who used Mint for years, I wanted to visualize my financial data on my TV dashboard but found no API available. That's why I developed a Tech-Stack Hack using Python and Google Cloud Platform (GCP) to integrate Mint with Google Sheets.
In this step-by-step guide, you'll learn how to set up a GCP account, extract Mint data using Python, insert the data into Google Sheets, and automate the entire process for less than $1 per month. Whether you want to display your financial data on your office TV or feed it to other destinations like SQL or Excel Online, this guide has got you covered.
While there is no official API for Mint, there is a grassroots development project on GitHub that offers a workaround that's the key to this solution. With Mint, Python, and GCP, you can streamline your finances and get real-time financial insights without breaking the bank.
Let's get started!
Do I need to be a developer to do this?
You don't need to be an experienced developer to complete this project as I'm not a developer myself. However, a basic understanding of APIs and software development or a passion for technology will be helpful. Everything I'm going to show you in this article, which includes code, you should be able to just copy and paste with minimal knowledge of Python programming language.
That being said, I highly recommend you learn Python and at least obtain the ability to edit existing code to fit your needs, it's an extremely powerful and simple programming language. This is a very detailed setup so please bring your patience and sense of adventure with you on this journey.
For this guide, we are going to build a Python application that logs into your Mint account, extracts the data for your accounts, and sends them to a Google Sheet once a day. Once you complete this guide, the sky is the limit on what's possible with your financial data and different ways to analyze it!
Let's define the technology stack we are using in this Tech-Stack Hack, I'm going to assume anyone reading this already knows what Google Sheets is and you can learn more about Mint and how to sign up for it here. Next, we will discuss the other components of the solution which are Python, Google Cloud Platform (GCP), and Docker (containers).
What is Python?
Python is a high-level, interpreted programming language that is widely used for web development, data analysis, artificial intelligence, and scientific computing. It is known for its simplicity, readability, and flexibility, making it a popular choice among developers of all skill levels.
Python is also an open-source language that is free to use and distribute. It is supported by a large community of developers who contribute to its development and maintenance.
In this Tech-Stack Hack, we will leverage the Mint API via Python, retrieve our financial data, and then write it to a Google Sheet all using the Google Cloud Platform as our environment.
What is Google Cloud Platform (GCP)?
Google Cloud Platform (GCP) is a suite of cloud computing services offered by Google. These services include computing power, storage, and application development tools, among others. GCP allows developers to build, test, and deploy applications on the same infrastructure that Google uses for its own products. It supports a variety of programming languages, including Python.
GCP also offers a variety of services such as Big Data, Machine learning, and storage. With GCP, we can easily scale and manage our application without worrying about the underlying infrastructure. In this guide, we will be using GCP to not only house our code within a docker container, but also schedule the program to run and monitor its health should any issues arise.
What are Docker and Containers?
Docker is a platform for developing, packaging, and deploying applications and dependencies into a container.
A container is a lightweight, standalone executable package that includes everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings. Because the container is self-contained, it can be easily moved from one environment to another, making it ideal for both development and deployment.
There are plenty of articles on Docker and container orchestration out there to learn more about this amazing technology. For the purposes of this simple tutorial however, you just need to know that Docker containerization is what we are going to use to package up our python code and place it in the GCP environment to run our automation on a schedule.
Phase 1: Setting Up Services
Mint
- Sign up for Mint here if you do not already have an account and then Sign in.
- Go to "Intuit account" settings
- Click on the "Sign in & security" box.
- Open the 'Authenticator" section and click on "Set up authenticator app". (Download the Google Authenticator app if you don't already have an existing authenticator app on your mobile device.)
- Copy and paste the 32-character key to a Notepad file to use later.
- Use the QR code to authenticate using your Authenticator app by entering the Plus symbol and QR code and then enter the 6-digit code and click the "Turn on" button to complete the setup.
- Go to the 2-step verification section, click "Set up" next to Phone number, select "Text message" and enter the code and password to complete the process. You should then see the box below that shows 2-step verification activated and the Authenticator app as PRIMARY method.
- Log back into Mint and start adding the financial institutions you want to track via the wizard as well as any budgets and other features you would like to use the platform for.
This will complete the Mint sign-up and setup section of this guide, every time you log into Mint it should be requiring you to enter the 6-digit code after your password is entered. Don't worry, we are going to use that 32-character key we saved earlier to automate the login process for the Mint API.
Google Cloud Platform (GCP)
For this setup, you will need a Google account to set up access to the GCP platform. If you do not have one, they are free to set up and you can sign-up for one here.
Once you have a Google account, go to GCP Console here.
- Click on the "Activate" button in the top right if this is your first time, this will start your $300 free credit trial in GCP.
- Create a Project - Click the "Select a project" dropdown from the home page
- Setup Billing - If you are on a free trial I believe you can skip this part for now, but eventually you will need to set up billing and make sure this project is associated with that billing account. Here is more info on how GCP billing works with projects.
- Enable Google Sheets API - Since we are going to stream our data to Google Sheets, we need to enable that API in GCP and then create credentials to use in our automation.
- Create Service Account - Next, we need to create a Service Account to authorize our automation to send data to Google Sheets
- In the main menu click on "APIs & Services" > "Credentials"
- Click on "Create Credentials" and then "Service account"
- Enter a Name for your service account and then click the "Copy" button to copy the service account email address it created. Be sure to save this somewhere like Notepad.
- Grant "Owner" roles to the service account and click "Done".
- Click on the "Keys" tab and click "Add Key" and then choose "JSON" as Key type. A JSON key file will be generated and downloaded automatically. Save this to a safe place as it will be used later in your automation.
Google Sheets
- Create a destination worksheet - Create a new Google Sheet and name it whatever you want, this is going to be where your Mint data ends up.
- Click the 'Share' button and share the sheet with the service account created above using the email as "Editor".
Phase 2: Environment Setup
We are now going to set up the GCP environment for our application and container-building process. This process is based on a fantastic article I found a few years back called "Dev to Prod in Three Easy Steps with Cloud Run" which does an excellent job of walking you through the entire process but with a 'hello world' Python app. If you get lost or this article leaves you with some questions, I highly suggest you do a walk-through of that tutorial to help.
- Open the GCP console and navigate to the Mint project you created earlier. Click the "Activate Cloud Shell" button on the top right as shown below. This is going to basically spin up a 'virtual machine' for you to use as your own GCP development environment and makes it easy to develop and deploy solutions across Google Cloud infrastructure.
- In the terminal type "gcloud auth list" and hit Enter and then click "Authorize" when the prompt displays. This grants access and should show your account listed as "Credentialed Accounts" once it authenticates. You may have to do this from time to time while on your project.
- In the terminal type "gcloud config list project" and hit Enter and verify you see your Mint project name listed.
- We are going to set up some environment variables to make things a little easier later. Keep this saved somewhere as you will use it every time you want to come in and make changes to the code. In the terminal enter the following variables and hit Enter (nothing should happen after you hit Enter other than a new terminal line is ready for the next input):
- export PROJ=$GOOGLE_CLOUD_PROJECT
export APP=mintdemo202302
export PORT=8080
export REGION="us-west1"
export TAG="gcr.io/$PROJ/$APP" - Here is a quick breakdown of the variables, I'm not an expert in this area and simply sharing what worked for me from trial and error.
- PROJ=$GOOGLE_CLOUD_PROJECT - Environment variable called
PROJ
and assigns it the value of theGOOGLE_CLOUD_PROJECT
variable, which is a built-in environment variable in GCP Cloud Shell that represents the ID of your current project. - APP=mintDemo202302 - Environment variable called
APP
and assigns it the valuemintDemo202302
. This variable represents the name of your application. You should change this to whatever you want it to be. - PORT=8080 - Environment variable called
PORT
and assigns it the value8080
. This variable represents the port number your application will listen on. - REGION="us-west1" - environment variable called
REGION
and assigns it the value"us-west1"
. This variable represents the region where your application will run. You can set this variable to the appropriate region for your application, such as"us-east1"
or"us-central1"
. - TAG="gcr.io/$PROJ/$APP" - Environment variable called
TAG
and assigns it the value"gcr.io/$PROJ/$APP"
. This variable represents the tag for your Docker image, which is used to identify and manage your container images in the Google Container Registry (GCR). The tag is set togcr.io/$PROJ/$APP
, which is a standard format for GCR image names, where$PROJ
represents your GCP project ID and$APP
represents your application name.
- PROJ=$GOOGLE_CLOUD_PROJECT - Environment variable called
- export PROJ=$GOOGLE_CLOUD_PROJECT
- Enable the APIs - Enter the following command in the terminal and hit Enter and you should receive an Operation finished successfully message when it's done. This command enables the necessary GCP APIs needed for building, storing, and running your container images in the Google Cloud Platform:
- gcloud services enable cloudbuild.googleapis.com \
containerregistry.googleapis.com \
run.googleapis.com - Here is a quick breakdown of the command lines:
- The cloudbuild.googleapis.com API allows you to build your container images using Cloud Build, the containerregistry.googleapis.com API enables you to store your container images in Google Container Registry, and the run.googleapis.com API enables you to deploy and run your containerized applications on Google Cloud Run.
By enabling these APIs, you are giving yourself access to the necessary tools and services to build, store, and deploy your containerized applications in GCP.
- The cloudbuild.googleapis.com API allows you to build your container images using Cloud Build, the containerregistry.googleapis.com API enables you to store your container images in Google Container Registry, and the run.googleapis.com API enables you to deploy and run your containerized applications on Google Cloud Run.
- gcloud services enable cloudbuild.googleapis.com \
At this point, you have your GCP environment set up and ready to start writing Python code for your project. The next phase involves using the 'Editor' module in GCP which has a more familiar file format and looks much like Visual Studio Code if you are familiar with that application. This is where we will enter our actual Python code.
Phase 3: Python Setup
Before we dive into code, it's important to note that for this tutorial, I will provide you with the basic Python scripts to copy and paste into the GCP environment. Since GCP can run Python, it will be easiest to show you the code in its built-in editor. However, to customize and troubleshoot the Python scripts involved for your own specific needs, you should set up a local Python environment on your own machine.
Python is easy to install and comes with many powerful tools for code development and debugging. I recommend that you install Python 3 and an IDE such as Visual Studio Code or PyCharm. If you want to learn more about setting up Python environments and Python in general, I highly suggest you visit Real Python. Additionally, YouTube has no shortage of great videos on all things Python for you to check out when you are ready.
Once you have set up your own Python environment, you can use it to modify the code provided in this guide and make any necessary changes to suit your needs.
Now, let's dive into the code in GCP's built-in development environment. First, we are going to create the base files needed for your application to run.
- Click the "Open Editor" button on the top bar of the Cloud Shell Terminal window and wait for the Editor to open.
- Open the Project folder and add 6 empty files shown below, you can add files by right-clicking on the project folder and clicking "New File". Click the link in each file to get the code from my GitHub repo to populate in your solution.
- config.py - Used to store your Mint username/password and MFA token you saved when setting up your Mint account.
- Dockerfile - Dockefiles contain the instructions for building a Docker image (your application container).
- main.py - Contains a basic Flask app that will execute the primary Mint API script as a web service.
- mint_secret.py - This is the JSON file you downloaded when creating your Google service account earlier, simply copy and paste it into this file.
- mintapiMain.py - This is the primary code for the Mint API, this is the code you will modify to suit your needs. This code essentially creates a Selenium instance that logs into your Mint account and allows you to retrieve your data.
- requirements.txt - This file is used to specify any dependencies the application needs to run, there are a variety of tools and libraries running in this solution and this file makes sure your Docker image loads all the necessary dependencies.
config.py
This is called from the main Python script to initiate the login to your Mint account. Be sure to concatenate the 32 characters into a single string for your MFA token you saved during the Mint account setup
username = 'your_mint_username'
password = 'your_mint_password'
mfa_token = 'your_32_character_mfa_token'
Dockerfile
As mentioned the Dockerfile contains instructions to build the Docker container that your automation will run inside when it's started. This may be one of many ways to build a Dockerfile for this solution so adjust as you see fit.
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y gnupg
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
RUN apt-get update \
&& apt-get install -y wget \
&& rm -rf /var/lib/apt/lists/*
# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable
RUN apt-get install unzip
RUN apt-get update && apt-get -qq -y install curl
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "mintapiMain.py"]
mint_secret.json
This is the JSON file generated when you created the Mint service account earlier. Simply copy and paste everything as-is into this file, it should look similar to the JSON shown below.
{
"type": "service_account",
"project_id": "mint-to-sheets-demo",
"private_key_id": "bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxb6",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIExxxxxxxxxxxxxxxxxxxxxxxxxxxxx+xW/fi7DbzamZUiymrBAu6bcgZB3Jtz1fh3JjFLJ/HLS580Pt\nKmSlDRc0HQfsqCuxZev/PQ==\n-----END PRIVATE KEY-----\n",
"client_email": "mint-demo-2023@mint-to-sheets-demo.iam.gserviceaccount.com",
"client_id": "107xxxxxxxxxxxxxxxx248320",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/mint-demo-2023%40mint-to-sheets-demo.iam.gserviceaccount.com"
}
main.py
This code creates a small Flask app that calls the mintapiMain
.py script which performs the actual extraction of Mint data and inserts it into Google Sheets. The Flask app listens for incoming connections on a specified port and runs the mintapiMain script when a connection is made. This code returns a success message indicating that the process has been completed. This code is helpful for making the Docker and Cloud Run processes more streamlined and automated.
from flask import Flask, request
import os
import mintapiMain
app = Flask(__name__)
PORT = os.environ.get("PORT") # Get PORT setting from the environment.
@app.route('/')
def index():
file = open('mintapiMain.py','r').read()
exec(file)
#return the success messages
return 'Process Completed!'
# This code ensures that your Flask app is started and listens for
# incoming connections on the local interface and port 8080.
if __name__ == "__main__":
app.run(host="0.0.0.0", port=PORT)
mintapiMain.py
This is the primary Python script that runs your application. This file is what you will modify as you scale your solution by adding more Mint data. In this guide, we are going to simply pull in the Accounts object that will list the financial accounts you have linked to your Mint account and load it to a Sheets file called "Mint Accounts".
import mintapi
import pandas as pd
import gspread
import time
import datetime
from datetime import timedelta
from df2gspread import df2gspread as d2g
from oauth2client.service_account import ServiceAccountCredentials
from config import username, password, mfa_token
from pandas import json_normalize
mint = mintapi.Mint(
username, # Email used to log in to Mint
password, # Your password used to log in to mint
# Optional parameters
mfa_method='soft-token', # See MFA Methods section
# Can be 'sms' (default), 'email', or 'soft-token'.
# if mintapi detects an MFA request, it will trigger the requested method
# and prompt on the command line.
mfa_input_callback=None, # see MFA Methods section
# can be used with any mfa_method
# A callback accepting a single argument (the prompt)
# which returns the user-inputted 2FA code. By default
# the default Python `input` function is used.
mfa_token=mfa_token, # see MFA Methods section
# used with mfa_method='soft-token'
# the token that is used to generate the totp
intuit_account=None, # account name when multiple accounts are registered with this email.
headless=True, # Whether the chromedriver should work without opening a
# visible window (useful for server-side deployments)
# None will use the default account.
session_path=None, # Directory that the Chrome persistent session will be written/read from.
# To avoid the 2FA code being asked for multiple times, you can either set
# this parameter or log in by hand in Chrome under the same user this runs
# as.
imap_account=None, # account name used to log in to your IMAP server
imap_password=None, # account password used to log in to your IMAP server
imap_server=None, # IMAP server host name
imap_folder='INBOX', # IMAP folder that receives MFA email
wait_for_sync=False, # do not wait for accounts to sync
wait_for_sync_timeout=300, # number of seconds to wait for sync
use_chromedriver_on_path=True, # True will use a system provided chromedriver binary that
# is on the PATH (instead of downloading the latest version)
)
time.sleep(10)
#Get accounts data
accounts = mint.get_account_data()
df_accounts = json_normalize(accounts)
#Budgets Dataframe to Google Sheets
scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
"https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name('mint_secret.json', scope)
client = gspread.authorize(creds)
# Send the accounts data to google sheets, use the ID in the URL that is after the docs.google.com/spreadsheet/d/<id>
spreadsheet_key_accounts = '<id>'
d2g.upload(df_accounts,spreadsheet_key_accounts,credentials=creds,row_names=True)
In this example, we are sending our Account data to Google Sheets using a library called df2gspread. The last section needs the Google Sheet key that is in the URL to find it in your Google Drive directory. See the image below for an example.
requirements.txt
The requirements.txt file list all the dependencies or external packages that your project requires in order to run. Each line in the file specifies the name of a package that is required to run your application. You can often add a version number as well but for the this tutorial we will just list the packages and it will pull the latest when it builds the container.
flask==2.0.2
gunicorn==20.1.0
df2gspread==1.0.4
gspread==5.3.2
mintapi==2.12
pandas==1.4.2
selenium
At this point, we have all the ingredients loaded to complete your automation! We have the environment setup, and the code/script files loaded into GCP, and now we just need to set up your container engine using Google's Cloud Run platform. Cloud Run provides a fully managed, scalable environment for running containerized applications, where the developer can focus on writing code rather than managing servers. It automatically scales up or down to handle traffic, and charges only for the exact amount of compute resources used.
Step 4: Cloud Run Setup
Cloud Run provides a fully managed, scalable environment for running containerized applications, where the developer can focus on writing code rather than managing servers. It automatically scales up or down to handle traffic, and charges only for the exact amount of compute resources used. There are 3 ways to setup Cloud Run in GCP; via the gcloud command line (which we are going to do here), using the rich web user interface in the GCP console and also programmatically via Google client libraries. If you would like to see how to do it via the web interface, you can check out this section here of the article I supplied above.
- Open the Cloud Shell Terminal and type cd and then your <folder name>. For instance, my folder is called "Mint_API_Demo" so I'm going to type cd Mint_API_Demo. If you want to see what folders are in your root directory (or whatever directory you are currently in) just type ls and hit Enter, this will list what is in your current working directory.
- Copy and paste the following commands and hit Enter (this is making sure your variables are active).
export PROJ=$GOOGLE_CLOUD_PROJECT
export APP=mintdemo202302
export PORT=8080
export REGION="us-west1"
export TAG="gcr.io/$PROJ/$APP" - Copy and paste this command and hit "Enter".
gcloud builds submit --tag $TAG
This will initiate the build of your container using the instructions in the Docker and requirements.txt files. This will take several minutes to run but hopefully, it looks like the image below when completed. If you get errors it's likely caused by missing libraries or dependencies in your Dockerfile. This is where I usually just get help from ChatGPT. - Once you have successfully built your image, it's time to deploy it to Google Cloud Run. Copy and paste the commands below and hit "Enter".
gcloud run deploy "$APP" \
--image "$TAG" \
--platform "managed" \
--region "$REGION" \
--allow-unauthenticated \
--memory 1G
These commands are deploying an application to Cloud Run, giving it a name of whatever $APP variable is using an image named whatever $TAG variable is and then managed by Google and the region it should run in. The allow-unauthenticated specifies that requests can be made to the service by unauthenticated users. You can change any of these settings to fit your needs. - Once the Cloud Run service initializes you should see a "Service URL" as shown below. Click on this URL and you will see an empty web page load and run for a few minutes. It should say "Process Completed" on the web page and your Google Sheet should have some fresh data from your Mint account!
Step 5: Scheduling your app
Once you have your new Python application running as expected, you need to create a schedule so it runs automatically for you throughout the day. I'm going to show you how to set up a single schedule for 6 am PDT, but using unix-cron schedule formatting you can create whatever schedule you want.
- In GCP menu find the "Cloud Scheduler" and click "Create a job".
- Fill out the Name, Region, Description and Frequency fields as you see fit or as shown below and click "Continue".
- In the "Configure the execution" section choose Target type of "HTTP", put in your Service URL from your Cloud Run setup, and set the HTTP method to "GET". Click "CREATE" and then run some tests to make sure it executes as expected.
Let's wrap this up!
I know there was a lot to unpack in this guide so be sure to give yourself a big pat on the back if you successfully saw your Mint data land in Google Sheets as expected! Hopefully, this Tech-Stack Hack should empower you to continue the journey and add even more financial data to Google Sheets or other destination data platforms that you prefer to work with.
I like to visualize mine on my giant TV dashboard in my home office, which you can read more about here.
By leveraging Python and Google Cloud Platform (GCP) to integrate Mint with Google Sheets, you can extract Mint data, insert it into Google Sheets, and automate the entire process for less than $1 per month.
Although Mint lacks an official API, I have provided you with a solution that leverages the powerful community behind the GitHub MintAPI repository that is the key to this Tech-Stack Hack. While you don't need to be an experienced developer to complete this step-by-step project you should be prepared to get into some of the weeds with Python, GCP, and Docker containers. You will come out the other side more knowledgeable and confident and a true Tech-Stack Hacker!
As we continue to see an uncertain financial economic outlook in the coming years, having real-time access and visualization of your key financial data is going to be vital to survive whatever happens.
So why wait? Let's get started and take control of our finances today!