As a developer, I found myself deep in the trenches of building a feature called "Receipt Radar." What seemed like a straightforward task - extracting receipt data from Gmail - quickly turned into a labyrinth of complex documentation, confusing OAuth processes, and the intricate dance of access and refresh tokens.
I vividly remember the frustration of sifting through Google's API documentation, trying to decipher how to generate access tokens, manage refresh tokens, and navigate the maze of Gmail's API ecosystem.
I thought to myself, "There has to be a better way. Why should every developer go through this struggle?" That's when I decided to create a Python library that would shield other developers from the complexities I faced.
Receiptor is the culmination of my journey - a straightforward Python-based solution designed to extract, parse, and structure Gmail receipt and invoice data. It's built with one goal in mind: to let developers integrate Gmail receipt data ingestion functionality easily, without the need to juggle through Gmail documentation or spend hours looking at examples.
In today's digital age, Gmail has become a primary tool for tracking purchases, managing expenses, and storing important financial information. Every day, millions of people receive receipts, invoices, and order details through their Gmail accounts. For developers building personal finance apps, expense management software, or business analytics tools, accessing this data efficiently is crucial.
Receiptor addresses the challenges I faced head-on:
1.No More API Confusion: Say goodbye to the days of deciphering multiple Gmail APIs. Receiptor handles all the complex interactions behind the scenes.
2.OAuth Made Easy: Remember my struggle with understanding Google OAuth? Receiptor simplifies this process, making it straightforward to set up and manage authentication.
3.Effortless Data Extraction: With just a few lines of code, you can now fetch, parse, and structure receipt data from Gmail. No more headaches trying to navigate through email content and attachments.
4.Structured Output: Receiptor doesn't just extract data; it presents it in a clean, structured format ready for your application to use.
I built Receiptor because I believe that developers should focus on creating amazing features and applications, not on wrestling with API documentation. By encapsulating my learnings and solutions into this library, I hope to save other developers the time and frustration I experienced. Whether you're building the next big fintech app, a simple expense tracker, or anything in between, Receiptor is designed to be your go-to tool for Gmail receipt data extraction. It's my way of contributing to the developer community and making our collective lives a little easier.
1. Fetching and Parsing Data with Minimal Code
Receiptor provides a clean, straightforward implementation to interact with Gmail and extract receipt data. With only a few lines of code, developers can set up Receiptor and fetch receipt information directly from their Gmail accounts. Here’s a quick overview:
2. Set Up Gmail Access
Receiptor requires a Gmail access token, which can be obtained using OAuth2. This token enables secure and authenticated access to Gmail data .
In order to create generate an access token you will have to configure an OAuth application in Google Cloud Platform (GCP) and set up the OAuth 2.0 flow in our application to work with it.
Create an account with GCP here: https://cloud.google.com
Once you open the link click on Console as you can see in the image above.
If you have already created a project then you may see the screen below .
Note : If you are new to GCP try to follow the documentation provided by GCP on how to create your first project : Documentation OR You can go through this blog on medium that will simpilfy the process : BLog
Once you have created your project or you are already logged into one of your project on GCP .
Start by navigating to your project API & Services > Credentials in GCP to create a new OAuth application.
You can directly type in the search bar credentials and you can navigate to credentials by clicking on it .
To create the credentials click on this create credentails button , which looks like this .
Once you click on create credentials , select oAuth client ID.
Note - If you are creating an credential for the first time you have to first configure consent screen .
Once you have configured the consent screen , continue the process to setup credentials given below .
Once you click on create credentials , you would be directed to this page .
Here you have to select your application type . I am working on a blog to let you know how to setup and utilise oauth 2 for different type of applications . In this blog I we will go through how to setup oauth2 credentials for web application .
Once you click on web application , you would shown following details .
Here you have to fill 2 main sections Name and Authorized redirect URIs .
Initially you can type the name of your choice like receiptor_test , or any name of your choice .
Now just click on create , regarding the redirect URI we will see how can we add this redirect URI ,and the credentials would be created .
As you can see the credentials is created and you are provided with CLIENT ID , CLIENT SECRET , you can also download these credentials locally by clicking on DOWNLOAD JSON.
Once you have pasted the code into your python file . Create an .env file like given below.
Paste all of your credentials line CLIENT_ID , CLIENT_SECRET .
For the redirect URI use this value : http://127.0.0.1:8080/test
Because we would be utilising uvicorn and port 8080 to execute the above code .
Once you have set the values in .env file , go to credentials on your GCP account and paste this value of redirect URI as show below.
Pass the API keys into the function.
Note : org_id is optional , if you are using any organisation project then you may require this org_id , which can be obtained through open ai account dashboard. For more information you can go through open ai official (documentation)[https://platform.openai.com/docs/api-reference/making-requests]
Obtain a Gmail access token through the OAuth2 flow. Store this token securely.
Main Data
Attachment Raw Text
Structured Document Data
With just these steps, Receiptor handles the complexity of interacting with multiple Gmail APIs, fetching the required emails, and retrieving all relevant information, including attachments.
Receiptor is more than just a library; it's a solution born from real-world developer challenges.Hope receiptor makes your life easy for build data ingestion pipeline from gmail !! I hope that Receiptor helps you build amazing things without the headaches I encountered. Happy coding!
View All Blogs
Connect with Hushh
Say something to reach out to us
Connect with hushh
Say something to reach out to us