Python package to interact with Google Suite APIs
Project description
Google Suite
Python library to automate handling of various Google Suite APIs such as Gmail, Blogger, etc.
Setup
- Make sure you have your Google token and credentials for your project from Google Cloud. You can follow the steps here to get started. You'll have to enable the Blogger api also.
gmail.py
Quick overview of the methods:
| Name | Description | Arguments |
|---|---|---|
| list_labels | List of labels (returns a dict) | None |
| create_label | Creates a label | label_name: str |
| update_label | Updates a label | label_name: str, new_label_name: str, label_visibility: LabelListVisibility, message_visibility: MessageListVisibility |
| delete_label | Deletes a label | label_name: str |
| label_by_id | Gets a label by id | label_name: str |
| label_by_name | Gets a label by name | msg_label_list: list |
| mark_read | Marks an email as read by id | msg_id: str |
| mark_all_read | Marks all emails as read given a label or sender or both | label_id: str = None, sender: str = None |
| mark_unread | Marks an email as unread by id | msg_id: str |
| list_messages | List of messages | None |
| send_message | Sends a message that can have with or without an attachment. If provided a threadId it will also reply within the email thread chain. | from_sender: str, to: str, subject: str, message_text: str, file: str = None, thread_id: str = None |
| download_attachment | Downloads an attachment and puts it in the attachments directory. Returns the path of the attachment. Also marks the email as read | label_name: str = None, sender: str = None |
| download_attachments | Download attachments from a list of messages using a ThreadPool and puts it in the attachments directory. Returns the path of the attachment. Also marks the email as read | messages: list[Message] |
| list_filters | List of filters | None |
| get_filter | Get a filter by id | filter_id: str |
| create_filter | Creates a filter | label_name: str = None, remove_from_inbox: bool = None, filter_from: str = None, subject: str = None, query: str = None, negatedQuery: str = None |
| update_filter | Updates a filter | label_name: str, new_label_name: str = None, label_visibility: LabelListVisibility = None, message_visibility: MessageListVisibility = None |
| delete_filter | Deletes a filter | filter_id: str |
from google_suite import Gmail
Gmail.list_labels()
# {'CHAT': 'CHAT',
# 'SENT': 'SENT',
# 'INBOX': 'INBOX',
# etc...
# 'Unwanted': 'Label_9'}
blogger.py
The blogger.py file contains methods to interact with the Blogger API:
| Method | Description | Arguments |
|---|---|---|
| list_blogs | Lists all blogs by the user. | None |
| list_posts | Lists all posts in a specific blog. | None |
| get_post_content | Retrieves the content of a specific post. | post_id: str |
| search_post | Searches for posts based on a query. | query: str |
| insert_post | Inserts a new post in the blog. | title: str, content: str |
| delete_post_by_id | Deletes a post by its ID. | post_id: str |
| delete_post_by_title | Deletes a post by its title. | title: str |
| list_comments | Lists comments for a specific post. | post_id: str |
| get_comment_by_id | Retrieves a comment by its ID. | post_id: str, comment_id: str |
| list_comments_by_blog | Lists comments for the entire blog. | None |
| mark_as_spam | Marks a comment as spam. | post_id: str, comment_id: str |
| mark_as_not_spam | Marks a comment as not spam. | post_id: str, comment_id: str |
from google_suite import Blogger
Blogger.list_blogs()
# {'kind': 'blogger#blogList',
# 'items': [{'kind': 'blogger#blog',
# 'id': '63.....',
# 'status': 'LIVE',
# 'name': 'The coolest blog ever',
# 'description': '',
# 'published': '2023-10-18T06:58:29-07:00',
# 'updated': '2024-03-12T10:20:35-07:00',
# 'url': 'http://tedfulk.blogspot.com/',
# 'selfLink': 'https://blogger.googleapis.com/v3/blogs/63.....',
# 'posts': {'totalItems': 2,
# 'selfLink': 'https://blogger.googleapis.com/v3/blogs/63...../posts'},
# 'pages': {'totalItems': 0,
# 'selfLink': 'https://blogger.googleapis.com/v3/blogs/63...../pages'},
# 'locale': {'language': 'en', 'country': '', 'variant': ''}}]}
Utilizing the Service Object
The util.py file builds the service object to interact with the Google APIs. Ensure that the project is set up in the Google Cloud Platform, and the necessary permissions and correct access to the scopes for the APIs are granted.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_suite-0.1.4.tar.gz.
File metadata
- Download URL: google_suite-0.1.4.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.13 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0464cdfd33029589e973c6a6a3f5d72632346cc03ba7fa39acdb2cf76d7bc710
|
|
| MD5 |
05eec03029bd7fe516bcc8def4cc9a88
|
|
| BLAKE2b-256 |
d30ef4ba500eebab93a658301e93b534dc1270a698ea26e01d40caf872c83a6c
|
File details
Details for the file google_suite-0.1.4-py3-none-any.whl.
File metadata
- Download URL: google_suite-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.13 Darwin/23.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba5e0573cb648ac5c26d0d5b8c1ff5031b89f9fe2b7c56f2cda75b7ce5f5ccf9
|
|
| MD5 |
6e74ac4411792efa6258ef88ca528763
|
|
| BLAKE2b-256 |
49599eebe6ec783d7a632d47b961cb1853310937a69b2dace941df246ba18ed7
|