The CLI version of gfetch-web!
This app helps you create local backups of your Gmail emails. It saves raw .eml files, cleaned .txt files, and attachments, each to their own directory.
It is built using Python and the Gmail API.
Note
The following instructions assume you are using uv.
uvx gfetch
Note
You will not be able to download emails without a valid credentials.json
file (see Setting up Google Cloud).
Warning
Invoking gfetch in this way will create a directory called gfetch
and its subdirectories in your current working directory!
git clone [email protected]:jwjacobson/gfetch-cli.git
Navigate to the gfetch-cli
directory:
cd gfetch-cli
Install dependencies:
uv sync
Create a .env
file from the provided template:
cp env-template .env
If you use the default values from env-template, the project layout will be as follows:
src
└── gfetch
├── cleaned_emails
│ └── attachments
├── raw_emails
├── credentials.json
└── token.json
(.py files omitted for clarity)
Note
- The
cleaned_emails
,raw_emails
, andattachments
directories are not part of the repo, but will be created when you run the app. - You have to manually download
credentials.json
(see Setting up Google Cloud below);token.json
will be generated automatically when you authenticate with the app.
Warning
credentials.json
contains sensitive data and should not be put in version control. It is already listed in .gitignore
but might not be covered if you change the filename.
For now, Gfetch requires you to create your own credentials to use it.
- Go to the Google Cloud Console and create an account if you don't have one.
- Using the navigation menu in the top-left of the screen, go to
APIs & Services
, thenEnable APIs and Services
. - Search
gmail
in the box and find the Gmail API, then enable it. - In the
APIs & Services
menu, clickCredentials
, then clickCreate Credentials
, thenOAuth Client ID
. - For application type, select
Desktop App
and name it how you desire -- perhapsgfetch
? - Follow the prompts to generate credentials.
- Once you've created the credentials, you must download them immediately, as you won't be able to access them again once you've left the confirmation screen. Download the credentials JSON and save it as
credentials.json
insrc/gfetch/
or yourgfetch
directory (if you're using uvx).
uv run gfetch
Or, if you have Just installed:
just run
Follow the onscreen instructions to back up your emails!
Note
At present, Gfetch only allows you to download all correspondence with a given address.
If you don't have a valid token (token.json
in the gfetch
folder), your default browser will open for you to authenticate with the account of your choice when you enter a correspondent's email.
To download emails, must grant access to your Gmail account to Gfetch. Gfetch only requires read-only access to Gmail account, and your emails are saved on processed on your hard drive. They are never stored elsewhere or used for any other purpose. For more details, see the terms of service and privacy policy.
Gfetch is free software, released under version 3.0 of the GPL. Everyone has the right to use, modify, and distribute gfetch subject to the stipulations of that license.