Google Workspace
Google Workspace is a high level unofficial API wrapper for some of the productivity related Google API's. This library has for now only implemented a client for Gmail, I hope to add Drive and much more in the near future.
Installation
You can install from pypi:
pip install -U google-workspace
Or get the latest updates (Not recommended for production):
pip install -U git+https://github.com/dermasmid/google-workspace.git
Documentation
Take a look at the full documentation here https://google-workspace.readthedocs.io/
Getting project credentials
You need to get a client secret file from the google console and you need to enable the api you want to use, just Google it.
After you saved the credentials json file to your workdir - you are all set!
Quick start's
Here you can see a few samples to get a feel of whats ahead.
Authenticate on your local machine
This snippet will run a authentication flow using the local_oauth method.
import google_workspace
service = google_workspace.service.GoogleService(
api="gmail",
session="my-gmail",
client_secrets="path/to/secrets/file"
)
service.local_oauth()
gmail_client = google_workspace.gmail.GmailClient(service=service)
print(gmail_client.email_address)
Authenticate a remote user
This snippet will run a authentication flow using the url_oauth method.
import google_workspace
service = google_workspace.service.GoogleService(
api="gmail",
session="my-gmail",
client_secrets="path/to/secrets/file"
)
service.url_oauth(
server_host="yourdomain.com",
block=True
)
gmail_client = google_workspace.gmail.GmailClient(service=service)
print(gmail_client.email_address)
Retrieve messages
This snippet will retrieve all messages from the inbox, print them to the console, mark them as read, and reply with a message saying "Hi!".
import google_workspace
gmail_client = google_workspace.gmail.GmailClient()
for message in gmail_client.get_messages("inbox"):
print(message)
message.mark_read()
message.reply("Hi!")
Send html email with attachments
This snippet will send a html email with attachments and then delete it from your sent messages.
import google_workspace
gmail_client = google_workspace.gmail.GmailClient()
sent_message = gmail_client.send_message(
to="test@test.com",
subject="This is fun!",
html="<b>HTML here</b>",
attachments=["image.png", "doc.pdf"]
)
gmail_client.delete_message(sent_message.get("id"))
Forward incoming messages
This snippet will forward all incoming messages which have "python" in thier subject.
import google_workspace
gmail_client = google_workspace.gmail.GmailClient()
def message_filter(history):
return "python" in history.message.subject
@gmail_client.on_message(labels="inbox", filters=[message_filter])
def handle_message(history):
history.message.forward(to="test@test.com")
Feedback and contributing
This library is very focused on being easy and fun to use, so if you find something that you think can be improved please open an issue or even better, a PR, thank you!
Metadata
Release files for google-workspace 0.20.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_workspace-0.20.3-py3-none-any.whl | Python 3 | none | any | Details for google_workspace-0.20.3-py3-none-any.whl |
Release files / google_workspace-0.20.3-py3-none-any.whl
| Download URL | google_workspace-0.20.3-py3-none-any.whl |
|---|---|
| Size | 58.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee036b7be50508ba3e082dd0ee86aa49681f1f8cd1c9d67f2d2901f291870ff3
|
|
BLAKE2b-256 checksum How to use checksums |
77b74d515c7bb8bb537b93980a2a01a68ecf22ad7685aa4512ad2df0f62fbca8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10
|
Security for google-workspace 0.20.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.