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 git@github.com:jwjacobson/gfetch-cli.gitNavigate to the gfetch-cli directory:
cd gfetch-cliInstall dependencies:
uv syncCreate a .env file from the provided template:
cp env-template .envIf 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, andattachmentsdirectories 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.jsonwill 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
gmailin the box and find the Gmail API, then enable it. - In the
APIs & Servicesmenu, clickCredentials, then clickCreate Credentials, thenOAuth Client ID. - For application type, select
Desktop Appand 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.jsoninsrc/gfetch/or yourgfetchdirectory (if you're using uvx).
uv run gfetchOr, if you have Just installed:
just runFollow 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.