Skip to main content

Gmail API Python Library

This library provides an easy way to interact with the Gmail API using Python. With this library, you can send emails with attachments, authenticate with the Gmail API, and manage your email accounts.

Usage

To use this library, you'll need to have a Google API Console project with the Gmail API enabled. You can follow the steps outlined in the Gmail API Quickstart Guide to set up your project.

The library requires the following dependencies:

google-api-python-client
google-auth-httplib2
google-auth-oauthlib

you can install these dependencies using pip:

pip install -r requirements.txt

You'll also need to have a credentials.json file for your API project, which you can download from the API Console.

You can use the following code to get started with the Gmail API:

from darkgmailapi import GmailApi

# Create a GmailApi object
gmail = GmailApi(credentials="path/to/credentials.json", send_email="you@example.com", token_file="path/to/token.pickle", scope="https://mail.google.com/")

# Build a message to send
message = gmail.build_message(destination="recipient@example.com",
                               obj="Subject of the email",
                               body="Body of the email")

# Send the message
gmail.send_message("me", message.as_bytes())

You can also attach files to your emails using the add_attachment method:

# Add an attachment to the message
gmail.add_attachment(message, "path/to/attachment.pdf")

to search for emails, you can use the search method:

# Search for emails
emails = gmail.search("search query")
# returns a list of messages

to get the body of an email, you can use the read_message method:

# Read the data of an email
message_data = gmail.read_message(emails[0])
# returns a dictionary with the email data, in this format
# {
#   "from": "",
#   "to": "",
#   "subject": "",
#   "date": "",
#   "body_html": "",
#   "body_text": ""
# }

to delete an email, you can use the delete_message method:

# Delete an email
gmail.delete_message(emails[0])

to read and unread emails, you can use the mark_as_read and mark_as_unread methods:

# Mark an email as read
gmail.mark_as_read(emails[0])

# Mark an email as unread
gmail.mark_as_unread(emails[0])

Metadata

Release files for darkgmailapi 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for darkgmailapi 0.0.4
File Size Uploaded
darkgmailapi-0.0.4.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for darkgmailapi 0.0.4
File Interpreter ABI Platform
darkgmailapi-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 35.5 kB

Release files / darkgmailapi-0.0.4.tar.gz

Download URL darkgmailapi-0.0.4.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0144571df2dc3ae1154ac7f37f66f044544d09619f0e8155694c79d68c671e6f
BLAKE2b-256 checksum
How to use checksums
72ea0109761eb627ce3f8901b60be682e75485c85b2b395312677d8d5fd63bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / darkgmailapi-0.0.4-py3-none-any.whl

Download URL darkgmailapi-0.0.4-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3594591fd358cc3f0a9b4560b9cdccd1dc1ed46270d690dfe147d373622bf746
BLAKE2b-256 checksum
How to use checksums
eb2cce7e1b161531de491c2cebe58b19ee563c27cb867092e7cde0bc0c09be36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page