Assign labels to emails in Google Mail based on their similarity to other emails assigned to the same label.
Project description
Sort your emails automatically
The pygmailsorter
is a python module to automate the filtering of emails on Gmail using the Gmail API. It assigns
labels to emails based on their similarity to other emails assigned to the same label.
Configuration
The pygmailsorter
stores the configuration files in the users home directory ~/.pygmailsorter
. This folder contains:
credentials.json
the authentication credentials for the Google API, which requires access to Gmail.token_files
the token directory is used to store the active token for accessing the APIs, these are created automatically, there should be no need for the user to modify these.email.db
a local SQLite database to store the emails and machine learning models to accelerate the sorting.
Installation
Install the package from github using pip
:
pip install git+https://github.com/jan-janssen/pygmailsorter.git
Finally, setup the credentials.json
in your Google Apps and store it in ~/.pygmailsorter/credentials.json
.
Python interface
Import the pygmailsorter
module
from pygmailsorter import Gmail
Initialize pygmailsorter
Create a gmail
object from the Gmail()
class
gmail = Gmail()
For testing purposes you can use the optimal client_service_file
parameter to specify the location of the
authentication credentials in case they are not stored in ~/.pygmailsorter/credentials.json
.
Download messages to pandas Dataframe
For offline processing it is helpful to download messages in bulk to pandas dataframes:
gmail.download_messages_to_dataframe(message_id_lst)
The message_id_lst
is a list of message ids, this can be obtained from gmail.search_email()
.
Get email content as dictionary
The content of the email rendered as python dictionary for further postprocessing:
gmail.get_email_dict(message_id)
The message_id
can be derived from a function like gmail.search_email()
.
Update database
Update local database stored in ~/.pygmailsorter/email.db
:
gmail.update_database(quick=False)
By setting quick
to True
only new emails are downloaded, with quick
set to False
all emails are downloaded.
Filter emails using machine learning
Assign new email labels to the emails with the label "MyLabel"
:
gmail.filter_label_by_machine_learning(
label="MyLabel", recalculate=True
)
By setting the optional parameter recalculate
to True
the machine learning models are fitted again to be up to date.
Command Line interface
The command line interface is currently rather limited, it supports the following options:
pygmailsorter -c/--config=~/.pygmailsorter
the configuration directory can be specified manually.pygmailsorter -d/--database
update the local email database.pygmailsorter -m/--machinelearning=MyLabel
assign new labels to the emails with labelMyLabel
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygmailsorter-0.0.1.tar.gz
.
File metadata
- Download URL: pygmailsorter-0.0.1.tar.gz
- Upload date:
- Size: 31.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db84bb436b4fed3956a5ee7d3063d61ea24271b29e0683f9d3cb3063baa530c5 |
|
MD5 | f7f2bdd5874b878081806c34a6ae17a6 |
|
BLAKE2b-256 | 40d95a50d800590a687c8c61f7ba7e7a609db7bd4434e8c161862f68366d0e14 |
File details
Details for the file pygmailsorter-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pygmailsorter-0.0.1-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b68ade1d888e8b7392795a3c90cde718f76f33b1b0440e77a8101dabe83801 |
|
MD5 | a26fe5bc8b955f02754cace4cf87f8c4 |
|
BLAKE2b-256 | 3a093b876eef3985a60c50f7a37c083eb1a9e2206434a711e0209cc5409ef14d |