{"id":13683173,"url":"https://github.com/loadsmart/gmail-wrapper","last_synced_at":"2025-04-14T22:26:59.235Z","repository":{"id":45447783,"uuid":"203424177","full_name":"loadsmart/gmail-wrapper","owner":"loadsmart","description":"📧 Because scrapping Gmail data doesn't have to be a pain ","archived":false,"fork":false,"pushed_at":"2024-07-31T18:50:22.000Z","size":109,"stargazers_count":30,"open_issues_count":2,"forks_count":5,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-03-28T10:47:32.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loadsmart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-20T17:35:11.000Z","updated_at":"2025-02-24T22:14:14.000Z","dependencies_parsed_at":"2024-01-14T16:08:51.731Z","dependency_job_id":"094d1ec6-817d-40ac-a258-29c73745e1c4","html_url":"https://github.com/loadsmart/gmail-wrapper","commit_stats":{"total_commits":78,"total_committers":9,"mean_commits":8.666666666666666,"dds":0.3846153846153846,"last_synced_commit":"43f48f8c384ce16c921f99439b2070549548e968"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Fgmail-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Fgmail-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Fgmail-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loadsmart%2Fgmail-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loadsmart","download_url":"https://codeload.github.com/loadsmart/gmail-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650769,"owners_count":21139684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T13:02:03.111Z","updated_at":"2025-04-14T22:26:59.205Z","avatar_url":"https://github.com/loadsmart.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Gmail Wrapper\n\n[![CircleCI](https://circleci.com/gh/loadsmart/gmail-wrapper/tree/master.svg?style=svg\u0026circle-token=110f54407b50c79865fe1f9b4352e213bc68504b)](https://circleci.com/gh/loadsmart/gmail-wrapper/tree/master)\n\nBecause scrapping Gmail data doesn't have to be a [pain](https://googleapis.github.io/google-api-python-client/docs/dyn/gmail_v1.html).\n\n## Installing\n\n```sh\npip install gmail-wrapper\n```\n\n## Developing\n\nCreate your [venv](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments)\n\n```sh\nvirtualenv .venv\nsource .venv/bin/activate\n```\n\nThen you can install the dependencies\n\n```sh\npip install -e .\n```\n\n## Testing\n\nSimply run\n\n```sh\nmake test\n```\n\n## Basic Usage\n\n- Setup the client\n\n```python\nfrom gmail_wrapper import GmailClient\n\nemail_account = \"john.doe@gmail.com\"\ncredentials_string = \"{...}\" # You must generate this on your Google account\nscopes = [GmailClient.SCOPE_READONLY]\nclient = GmailClient(email_account, secrets_json_string=credentials_string, scopes=scopes)\n```\n\n- Fetch messages\n\n```python\nimport sys\n\nquery = \"filename:pdf label:friends\" # Check Gmail query docs: https://support.google.com/mail/answer/7190\nmessages = client.get_messages(query=query, limit=10)\nfor message in messages:\n    print(\"-- MESSAGE {} --\".format(message.id))\n    print(\"SUBJECT: {}\".format(message.subject))\n    print(\"DATE: {}\".format(message.date))\n    for attachment in message.attachments:\n        print(\"\\t-- ATTACHMENT {} --\".format(attachment.id))\n        print(\"\\t\\tFILENAME: {}\".format(attachment.filename))\n        print(\"\\t\\tDECODED SIZE: {}\".format(sys.getsizeof(attachment.content)))\n```\n\n- Modify message labels\n\nIf a single message:\n\n```python\nmessage_id = \"...\"\nmessage = client.get_message(message_id)\nprint(message.labels) # [\"foo\", \"bar\"]\nmessage.modify(add_labels=[\"processed\"], remove_labels=[\"foo\"]) # Beware that you'll need proper scopes\nprint(message.labels) # [\"bar\", \"processed\"]\n```\n\nIf multiple messages:\n\n```python\nmessage_ids = [\"...\", \"...\"]\nmessage = client.modify_multiple_messages(message_ids, [\"processed\"], remove_labels=[\"foo\"])\n```\n\n- Archive a message\n\n```python\nmessage.archive() # Beware that you'll need proper scopes\n```\n\n- Send message\n\n```python\ncontent = '''\n\u003chtml\u003e\n    \u003ch1\u003eHey there\u003c/h1\u003e\n    \u003cp\u003eI am using gmail-wrapper lib!\u003c/p\u003e\n\u003c/html\u003e\n'''\n\nmessage = client.send(\n    subject=\"You will like it\",\n    html_content=content,\n    to=\"thanos@loadsmart.com\",\n    cc=[\"iron.man@loadsmart.com\", \"spider.man@loadsmart.com\"],\n    bcc=[\"wolverine@loadsmart.com\"]\n) # Beware that you'll need proper scopes\nprint(message) # Gmail message: ABC123\n```\n\n- Reply message\n\n```python\nmessage_id = \"...\"\nmessage = client.get_message(message_id)\n\nreply = '''\nI am out for vacation, will return \u003cstrong\u003eJan 14\u003c/strong\u003e.\n\nIf it is really important, you can call me, but think twice.\n'''\nresponse = message.reply(reply)\n```\n\n- Handle exceptions\n\nExceptions are part of every developer day-to-day. You may want to handle exceptions as follows:\n\n```python\nfrom gmail_wrapper.exceptions import (\n    MessageNotFoundError,\n    AttachmentNotFoundError,\n    GmailError,\n)\n\ntry:\n    do_something()\nexcept MessageNotFoundError as e:\n    print(f\"There is no message! {e}\")\nexcept AttachmentNotFoundError as e:\n    print(f\"There is no attachment! {e}\")\nexcept GmailError as e:\n    print(f\"Google servers are burning! {e}\")\n```\n\n## Disclaimer\n\nGmail is a trademark of Google. This open-source project is **not** an official library nor has any endorsement of Google.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsmart%2Fgmail-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floadsmart%2Fgmail-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floadsmart%2Fgmail-wrapper/lists"}