From c905e05a80fea6cd06189522d3f760cffd6c769d Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Wed, 21 Jul 2021 15:27:34 -0700 Subject: [PATCH 001/102] Remove newsletter badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index de23ef2f6..8b089aeb3 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![Travis Badge](https://travis-ci.com/sendgrid/sendgrid-python.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-python) [![codecov](https://img.shields.io/codecov/c/github/sendgrid/sendgrid-python/main.svg?style=flat-square&label=Codecov+Coverage)](https://codecov.io/gh/sendgrid/sendgrid-python) [![Docker Badge](https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg)](https://hub.docker.com/r/sendgrid/sendgrid-python/) -[![Email Notifications Badge](https://dx.sendgrid.com/badge/python)](https://dx.sendgrid.com/newsletter/python) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-python.svg)](https://github.com/sendgrid/sendgrid-python/graphs/contributors) From 25c3de49aea06a02b66ab2645583f52bc3c2881a Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Thu, 29 Jul 2021 14:29:36 -0700 Subject: [PATCH 002/102] chore: remove docker credentials for PRs --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 02c163356..2341f8631 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,9 @@ before_script: - chmod +x ./cc-test-reporter - "./cc-test-reporter before-build" script: -- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin + fi - make test-docker after_script: - make test-install From c99e8ea481bdc2c036f8fe9971c732ef3cb598a2 Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Thu, 29 Jul 2021 14:33:09 -0700 Subject: [PATCH 003/102] chore: revert removal of docker credentials for PRs --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2341f8631..02c163356 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,7 @@ before_script: - chmod +x ./cc-test-reporter - "./cc-test-reporter before-build" script: -- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin - fi +- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - make test-docker after_script: - make test-install From 4047acd5e131b3942308f7c09fb5577b9bf6aa15 Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Thu, 29 Jul 2021 14:46:56 -0700 Subject: [PATCH 004/102] chore: remove docker credentials for PRs --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 02c163356..76606df83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,9 @@ before_script: - chmod +x ./cc-test-reporter - "./cc-test-reporter before-build" script: -- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin +- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin; + fi - make test-docker after_script: - make test-install From 272274ae26943bf0d7433843dab914ab9fcb4993 Mon Sep 17 00:00:00 2001 From: vindarel Date: Fri, 30 Jul 2021 17:11:45 +0200 Subject: [PATCH 005/102] feat: add reply_to to helpers.Mail (#999) * Add reply_to to helpers.Mail Otherwise, we must create the Mail and then set the reply_to thanks to its setter. (and we have to dig the code to find out). * fix: tests: add missing import Co-authored-by: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> --- sendgrid/helpers/mail/mail.py | 7 +++++++ test/test_mail_helpers.py | 7 ++++++- use_cases/send_a_single_email_to_a_single_recipient.md | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index ba21f7891..ba04a2b5b 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -24,6 +24,7 @@ def __init__( self, from_email=None, to_emails=None, + reply_to=None, subject=None, plain_text_content=None, html_content=None, @@ -40,6 +41,8 @@ def __init__( :param to_emails: The email address of the recipient :type to_emails: To, str, tuple, list(str), list(tuple), list(To), optional + :param reply_to: The email address to reply to + :type reply_to: ReplyTo, tuple, optional :param plain_text_content: The plain text body of the email :type plain_text_content: string, optional :param html_content: The html body of the email @@ -79,6 +82,10 @@ def __init__( if html_content is not None: self.add_content(html_content, MimeType.html) + # Optional + if reply_to is not None: + self.reply_to = reply_to + def __str__(self): """A JSON-ready string representation of this Mail object. diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index 57a4ba880..49c58d05b 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -94,12 +94,13 @@ def test_batch_id(self): # Send a Single Email to a Single Recipient def test_single_email_to_a_single_recipient(self): - from sendgrid.helpers.mail import (Mail, From, To, Subject, + from sendgrid.helpers.mail import (Mail, From, To, ReplyTo, Subject, PlainTextContent, HtmlContent) self.maxDiff = None message = Mail( from_email=From('test+from@example.com', 'Example From Name'), to_emails=To('test+to@example.com', 'Example To Name'), + reply_to=ReplyTo('test+reply_to@example.com', 'Example Reply To Name'), subject=Subject('Sending with SendGrid is Fun'), plain_text_content=PlainTextContent( 'and easy to do anywhere, even with Python'), @@ -123,6 +124,10 @@ def test_single_email_to_a_single_recipient(self): "email": "test+from@example.com", "name": "Example From Name" }, + "reply_to": { + "email": "test+reply_to@example.com", + "name": "Example Reply To Name" + }, "personalizations": [ { "to": [ diff --git a/use_cases/send_a_single_email_to_a_single_recipient.md b/use_cases/send_a_single_email_to_a_single_recipient.md index 8a2364285..c469c3bd6 100644 --- a/use_cases/send_a_single_email_to_a_single_recipient.md +++ b/use_cases/send_a_single_email_to_a_single_recipient.md @@ -6,6 +6,7 @@ from sendgrid.helpers.mail import Mail message = Mail( from_email='from_email@example.com', to_emails='to@example.com', + reply_to='reply_to@example.com', subject='Sending with Twilio SendGrid is Fun', html_content='and easy to do anywhere, even with Python') try: From c0da90440f25c82648b0fda0d9e62f02ec8a55e8 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 11 Aug 2021 16:45:38 +0000 Subject: [PATCH 006/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90674eee0..ad87a42d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-08-11] Version 6.8.0 +-------------------------- +**Library - Feature** +- [PR #999](https://github.com/sendgrid/sendgrid-python/pull/999): add reply_to to helpers.Mail. Thanks to [@vindarel](https://github.com/vindarel)! + + [2021-06-16] Version 6.7.1 -------------------------- **Library - Chore** From 08f0670aa2a5d05cfe981e3584dcd491d469b26d Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 11 Aug 2021 16:52:36 +0000 Subject: [PATCH 007/102] Release 6.8.0 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 157048dac..ff52e2e6c 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.7.1' +__version__ = '6.8.0' From 62d43ed0b27c8f7eec6dad8fe3880b81be7b1d2c Mon Sep 17 00:00:00 2001 From: Shwetha Radhakrishna Date: Wed, 18 Aug 2021 12:57:37 -0500 Subject: [PATCH 008/102] chore: revert reply_to prop add in mail (#1003) Co-authored-by: Shwetha Radhakrishna --- sendgrid/helpers/mail/mail.py | 7 ------- test/test_mail_helpers.py | 9 ++------- use_cases/send_a_single_email_to_a_single_recipient.md | 1 - 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index ba04a2b5b..ba21f7891 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -24,7 +24,6 @@ def __init__( self, from_email=None, to_emails=None, - reply_to=None, subject=None, plain_text_content=None, html_content=None, @@ -41,8 +40,6 @@ def __init__( :param to_emails: The email address of the recipient :type to_emails: To, str, tuple, list(str), list(tuple), list(To), optional - :param reply_to: The email address to reply to - :type reply_to: ReplyTo, tuple, optional :param plain_text_content: The plain text body of the email :type plain_text_content: string, optional :param html_content: The html body of the email @@ -82,10 +79,6 @@ def __init__( if html_content is not None: self.add_content(html_content, MimeType.html) - # Optional - if reply_to is not None: - self.reply_to = reply_to - def __str__(self): """A JSON-ready string representation of this Mail object. diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index 49c58d05b..1598c607b 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -94,13 +94,12 @@ def test_batch_id(self): # Send a Single Email to a Single Recipient def test_single_email_to_a_single_recipient(self): - from sendgrid.helpers.mail import (Mail, From, To, ReplyTo, Subject, + from sendgrid.helpers.mail import (Mail, From, To, Subject, PlainTextContent, HtmlContent) self.maxDiff = None message = Mail( from_email=From('test+from@example.com', 'Example From Name'), to_emails=To('test+to@example.com', 'Example To Name'), - reply_to=ReplyTo('test+reply_to@example.com', 'Example Reply To Name'), subject=Subject('Sending with SendGrid is Fun'), plain_text_content=PlainTextContent( 'and easy to do anywhere, even with Python'), @@ -124,10 +123,6 @@ def test_single_email_to_a_single_recipient(self): "email": "test+from@example.com", "name": "Example From Name" }, - "reply_to": { - "email": "test+reply_to@example.com", - "name": "Example Reply To Name" - }, "personalizations": [ { "to": [ @@ -660,7 +655,7 @@ def test_personalization_add_email_filters_out_duplicate_to_emails(self): p.add_email(to_email) self.assertEqual([to_email.get()], p.tos) - + def test_personalization_add_email_filters_out_duplicate_to_emails_ignoring_case(self): self.maxDiff = None diff --git a/use_cases/send_a_single_email_to_a_single_recipient.md b/use_cases/send_a_single_email_to_a_single_recipient.md index c469c3bd6..8a2364285 100644 --- a/use_cases/send_a_single_email_to_a_single_recipient.md +++ b/use_cases/send_a_single_email_to_a_single_recipient.md @@ -6,7 +6,6 @@ from sendgrid.helpers.mail import Mail message = Mail( from_email='from_email@example.com', to_emails='to@example.com', - reply_to='reply_to@example.com', subject='Sending with Twilio SendGrid is Fun', html_content='and easy to do anywhere, even with Python') try: From 395f86d2feb04a00d510b4107e543edaf0506d80 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 25 Aug 2021 18:43:36 +0000 Subject: [PATCH 009/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad87a42d9..7ae148d6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-08-25] Version 6.8.1 +-------------------------- +**Library - Chore** +- [PR #1003](https://github.com/sendgrid/sendgrid-python/pull/1003): get rid of reply_to in mail helper. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + + [2021-08-11] Version 6.8.0 -------------------------- **Library - Feature** From e40816321149fa360de297eab49979c3e522c825 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 25 Aug 2021 18:48:28 +0000 Subject: [PATCH 010/102] Release 6.8.1 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index ff52e2e6c..c5a38a4f5 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.8.0' +__version__ = '6.8.1' From a9a80675937ff3b9d8d9719e95a0b87cb42929ae Mon Sep 17 00:00:00 2001 From: Shwetha Radhakrishna Date: Fri, 10 Sep 2021 12:05:00 -0500 Subject: [PATCH 011/102] chore: add tests for v3.9 (#1007) --- .travis.yml | 1 + README.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 76606df83..46f3601b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - version=3.6 - version=3.7 - version=3.8 + - version=3.9 global: - CC_TEST_REPORTER_ID=$TRAVIS_CODE_CLIMATE_TOKEN before_script: diff --git a/README.md b/README.md index 8b089aeb3..8ce206abb 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ We appreciate your continued support, thank you! ## Prerequisites -- Python version 2.7, 3.5, 3.6, 3.7, or 3.8 +- Python version 2.7+ - The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python) ## Setup Environment Variables From 14a07cd85a51d4c26d9fe828bb829dca5e2ad401 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 22 Sep 2021 21:05:13 +0000 Subject: [PATCH 012/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae148d6d..f4712dc13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-09-22] Version 6.8.2 +-------------------------- +**Library - Chore** +- [PR #1007](https://github.com/sendgrid/sendgrid-python/pull/1007): test against v3.9. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + + [2021-08-25] Version 6.8.1 -------------------------- **Library - Chore** From c22b7f6ca97a750ac68042d706ffd34af6fde429 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 22 Sep 2021 21:13:09 +0000 Subject: [PATCH 013/102] Release 6.8.2 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index c5a38a4f5..94859745c 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.8.1' +__version__ = '6.8.2' From 0d00f0dfe98a8c442c66f891f6fca18234418606 Mon Sep 17 00:00:00 2001 From: Shwetha Radhakrishna Date: Fri, 8 Oct 2021 06:51:53 -0700 Subject: [PATCH 014/102] docs: improve signed event webhook validation docs (#1013) --- TROUBLESHOOTING.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index b9a68b8c0..0a7f54c69 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -15,6 +15,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se * [Version Convention](#versions) * [Viewing the Request Body](#request-body) * [Error Handling](#error-handling) +* [Verifying Event Webhooks](#signed-webhooks) ## Environment Variables and Your Twilio SendGrid API Key @@ -117,3 +118,14 @@ You can do this right before you call `response = sg.client.mail.send.post(reque # Error Handling Please review [our use_cases](use_cases/README.md) for examples of error handling. + + +## Signed Webhook Verification + +Twilio SendGrid's Event Webhook will notify a URL via HTTP POST with information about events that occur as your mail is processed. [This](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) article covers all you need to know to secure the Event Webhook, allowing you to verify that incoming requests originate from Twilio SendGrid. The sendgrid-python library can help you verify these Signed Event Webhooks. + +You can find the usage example [here](examples/helpers/eventwebhook/eventwebhook_example.py) and the tests [here](test/test_eventwebhook.py). +If you are still having trouble getting the validation to work, follow the following instructions: +- Be sure to use the *raw* payload for validation +- Be sure to include a trailing carriage return and newline in your payload +- In case of multi-event webhooks, make sure you include the trailing newline and carriage return after *each* event From 77ae5f5c7ae69a49d9814d96ccc418a31c3271cd Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Mon, 11 Oct 2021 11:31:14 -0700 Subject: [PATCH 015/102] chore: pin starkbank-ecdsa version (#1015) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ff1ba3c35..37e68e9d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ PyYAML>=4.2b1 python-http-client>=3.2.1 six==1.11.0 pytest==3.8.2 -starkbank-ecdsa>=1.0.0 +starkbank-ecdsa>=1.0.0,<2.0.0 From 01b72926140af023bfa2546d09dbb3b9be126a90 Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Mon, 11 Oct 2021 13:41:24 -0700 Subject: [PATCH 016/102] chore: pin starkbank-ecdsa version (#1016) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b3eeec82d..8ec7329c8 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def getRequires(): deps = [ 'python_http_client>=3.2.1', - 'starkbank-ecdsa>=1.0.0' + 'starkbank-ecdsa>=1.0.0,<2.0.0' ] return deps From 3fdf07930123f494088ab276441d538ac11ef9fa Mon Sep 17 00:00:00 2001 From: Twilio Date: Mon, 18 Oct 2021 18:31:15 +0000 Subject: [PATCH 017/102] [Librarian] Version Bump --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4712dc13..53d21c256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-10-18] Version 6.8.3 +-------------------------- +**Library - Chore** +- [PR #1016](https://github.com/sendgrid/sendgrid-python/pull/1016): pin starkbank-ecdsa version. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #1015](https://github.com/sendgrid/sendgrid-python/pull/1015): pin starkbank-ecdsa version. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Library - Docs** +- [PR #1013](https://github.com/sendgrid/sendgrid-python/pull/1013): improve signed event webhook validation docs. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + + [2021-09-22] Version 6.8.2 -------------------------- **Library - Chore** From 2e12f1cc86f7fc59d1fd0cea0030d0213aee493f Mon Sep 17 00:00:00 2001 From: Twilio Date: Mon, 18 Oct 2021 18:35:05 +0000 Subject: [PATCH 018/102] Release 6.8.3 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 94859745c..b45da21b6 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.8.2' +__version__ = '6.8.3' From a97e83a15dffe41cd87f52316fe04502314aec39 Mon Sep 17 00:00:00 2001 From: Bilal Boussayoud Date: Mon, 25 Oct 2021 15:07:33 -0600 Subject: [PATCH 019/102] feat: allow personalization of the From name and email for each recipient (#1020) * feat: allow personalization of the From name and email for each recipient --- examples/helpers/README.md | 12 ++-- examples/helpers/mail_example.py | 65 ++++++++++++++++--- sendgrid/helpers/mail/personalization.py | 21 +++++- test/test_mail_helpers.py | 9 +++ use_cases/README.md | 1 + .../send_multiple_emails_personalizations.md | 32 +++++++++ 6 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 use_cases/send_multiple_emails_personalizations.md diff --git a/examples/helpers/README.md b/examples/helpers/README.md index df1746b52..8d7594d44 100644 --- a/examples/helpers/README.md +++ b/examples/helpers/README.md @@ -28,12 +28,16 @@ For more information on parameters and usage, see [here](../mail/mail.py) ### Creating Personalizations -To create personalizations, you need a dictionary to store all your email components. See example [here](https://github.com/sendgrid/sendgrid-python/blob/0b683169b08d3a7c204107cd333be33053297e74/examples/helpers/mail_example.py#L47) -After creating a dictionary, you can go ahead and create a `Personalization` object. +The personalization helper can be used to create personalizations and customize various aspects of an email. See example [here](mail_example.py) in `build_multiple_emails_personalized()`, and refer [here](https://docs.sendgrid.com/for-developers/sending-email/personalizations) for more documentation. ``` mock_personalization = Personalization() - for to_addr in personalization['to_list']: - mock_personalization.add_to(to_addr) + + for to_addr in personalization['to_list']: + mock_personalization.add_to(to_addr) + + mock_personalization.set_from(from_addr) + mock_personalization.add_cc(cc_addr) + # etc... ``` ### Creating Attachments diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py index 700970110..384181501 100644 --- a/examples/helpers/mail_example.py +++ b/examples/helpers/mail_example.py @@ -13,7 +13,7 @@ def build_hello_email(): from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException - message = Mail(from_email=From('from@example.com.com', 'Example From Name'), + message = Mail(from_email=From('from@example.com', 'Example From Name'), to_emails=To('to@example.com', 'Example To Name'), subject=Subject('Sending with SendGrid is Fun'), plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), @@ -26,25 +26,30 @@ def build_hello_email(): except SendGridException as e: print(e.message) - for cc_addr in personalization['cc_list']: + mock_personalization = Personalization() + personalization_dict = get_mock_personalization_dict() + + for cc_addr in personalization_dict['cc_list']: mock_personalization.add_to(cc_addr) - for bcc_addr in personalization['bcc_list']: + for bcc_addr in personalization_dict['bcc_list']: mock_personalization.add_bcc(bcc_addr) - for header in personalization['headers']: + for header in personalization_dict['headers']: mock_personalization.add_header(header) - for substitution in personalization['substitutions']: + for substitution in personalization_dict['substitutions']: mock_personalization.add_substitution(substitution) - for arg in personalization['custom_args']: + for arg in personalization_dict['custom_args']: mock_personalization.add_custom_arg(arg) - mock_personalization.subject = personalization['subject'] - mock_personalization.send_at = personalization['send_at'] - return mock_personalization + mock_personalization.subject = personalization_dict['subject'] + mock_personalization.send_at = personalization_dict['send_at'] + + message.add_personalization(mock_personalization) + return message def get_mock_personalization_dict(): """Get a dict of personalization mock.""" @@ -78,6 +83,36 @@ def get_mock_personalization_dict(): mock_pers['send_at'] = 1443636843 return mock_pers +def build_multiple_emails_personalized(): + import json + from sendgrid.helpers.mail import Mail, From, To, Cc, Bcc, Subject, PlainTextContent, \ + HtmlContent, SendGridException, Personalization + + # Note that the domain for all From email addresses must match + message = Mail(from_email=From('from@example.com', 'Example From Name'), + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + + mock_personalization = Personalization() + mock_personalization.add_to(To('test@example.com', 'Example User 1')) + mock_personalization.add_cc(Cc('test1@example.com', 'Example User 2')) + message.add_personalization(mock_personalization) + + mock_personalization_2 = Personalization() + mock_personalization_2.add_to(To('test2@example.com', 'Example User 3')) + mock_personalization_2.set_from(From('from@example.com', 'Example From Name 2')) + mock_personalization_2.add_bcc(Bcc('test3@example.com', 'Example User 4')) + message.add_personalization(mock_personalization_2) + + try: + print(json.dumps(message.get(), sort_keys=True, indent=4)) + return message.get() + + except SendGridException as e: + print(e.message) + + return message def build_attachment1(): """Build attachment mock. Make sure your content is base64 encoded before passing into attachment.content. @@ -308,6 +343,15 @@ def build_kitchen_sink(): return message +def send_multiple_emails_personalized(): + # Assumes you set your environment variable: + # https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key + message = build_multiple_emails_personalized() + sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message=message) + print(response.status_code) + print(response.body) + print(response.headers) def send_hello_email(): # Assumes you set your environment variable: @@ -334,5 +378,8 @@ def send_kitchen_sink(): ## this will actually send an email # send_hello_email() +## this will send multiple emails +# send_multiple_emails_personalized() + ## this will only send an email if you set SandBox Mode to False # send_kitchen_sink() diff --git a/sendgrid/helpers/mail/personalization.py b/sendgrid/helpers/mail/personalization.py index 21a31c863..a4e1c1de4 100644 --- a/sendgrid/helpers/mail/personalization.py +++ b/sendgrid/helpers/mail/personalization.py @@ -6,6 +6,7 @@ class Personalization(object): def __init__(self): """Create an empty Personalization and initialize member variables.""" self._tos = [] + self._from_email = None self._ccs = [] self._bccs = [] self._subject = None @@ -26,7 +27,10 @@ def add_email(self, email): if email_type.__name__ == 'Bcc': self.add_bcc(email) return - raise ValueError('Please use a To, Cc or Bcc object.') + if email_type.__name__ == 'From': + self.from_email = email + return + raise ValueError('Please use a To, From, Cc or Bcc object.') def _get_unique_recipients(self, recipients): unique_recipients = [] @@ -77,6 +81,17 @@ def add_to(self, email): self._tos.append(email.get()) + @property + def from_email(self): + return self._from_email + + @from_email.setter + def from_email(self, value): + self._from_email = value + + def set_from(self, email): + self._from_email = email.get() + @property def ccs(self): """A list of recipients who will receive copies of this email. @@ -236,6 +251,10 @@ def get(self): if value: personalization[key[:-1]] = value + from_value = getattr(self, 'from_email') + if from_value: + personalization['from'] = from_value + for key in ['subject', 'send_at', 'dynamic_template_data']: value = getattr(self, key) if value: diff --git a/test/test_mail_helpers.py b/test/test_mail_helpers.py index 1598c607b..a7d08d890 100644 --- a/test/test_mail_helpers.py +++ b/test/test_mail_helpers.py @@ -667,6 +667,15 @@ def test_personalization_add_email_filters_out_duplicate_to_emails_ignoring_case self.assertEqual([to_email.get()], p.tos) + def test_personalization_set_from_email(self): + self.maxDiff = None + + p = Personalization() + from_email = From('test+from@example.com', 'Example From') + p.set_from(from_email) + + self.assertEqual(from_email.get(), p.from_email) + def test_personalization_filters_out_duplicate_cc_emails(self): self.maxDiff = None diff --git a/use_cases/README.md b/use_cases/README.md index a91f1f5a4..f9fe2470e 100644 --- a/use_cases/README.md +++ b/use_cases/README.md @@ -8,6 +8,7 @@ This directory provides examples for specific use cases of this library. Please * [Send a Single Email to a Single Recipient](send_a_single_email_to_a_single_recipient.md) * [Send a Single Email to Multiple Recipients](send_a_single_email_to_multiple_recipients.md) * [Send Multiple Emails to Multiple Recipients](send_multiple_emails_to_multiple_recipients.md) +* [Send Multiple Emails with Personalizations](send_multiple_emails_personalizations.md) * [Kitchen Sink - an example with all settings used](kitchen_sink.md) * [Transactional Templates](transactional_templates.md) * [Attachments](attachment.md) diff --git a/use_cases/send_multiple_emails_personalizations.md b/use_cases/send_multiple_emails_personalizations.md new file mode 100644 index 000000000..e8a7e2eec --- /dev/null +++ b/use_cases/send_multiple_emails_personalizations.md @@ -0,0 +1,32 @@ +```python +import os +import json +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail, Personalization, From, To, Cc, Bcc + +# Note that the domain for all From email addresses must match +message = Mail( + from_email=('from@example.com', 'Example From Name'), + subject='Sending with Twilio SendGrid is Fun', + html_content='and easy to do anywhere, even with Python') + +personalization1 = Personalization() +personalization1.add_email(To('test0@example.com', 'Example Name 0')) +personalization1.add_email(Cc('test1@example.com', 'Example Name 1')) +message.add_personalization(personalization1) + +personalization2 = Personalization() +personalization2.add_email(To('test2@example.com', 'Example Name 2')) +personalization2.add_email(Bcc('test3@example.com', 'Example Name 3')) +personalization2.add_email(From('from2@example.com', 'Example From Name 2')) +message.add_personalization(personalization2) + +try: + sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message) + print(response.status_code) + print(response.body) + print(response.headers) +except Exception as e: + print(e.message) +``` \ No newline at end of file From 5e9b0ff061a3cb888f7089473b7039432b748f37 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 3 Nov 2021 18:51:55 +0000 Subject: [PATCH 020/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53d21c256..8004be4db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-11-03] Version 6.9.0 +-------------------------- +**Library - Feature** +- [PR #1020](https://github.com/sendgrid/sendgrid-python/pull/1020): allow personalization of the From name and email for each recipient. Thanks to [@beebzz](https://github.com/beebzz)! + + [2021-10-18] Version 6.8.3 -------------------------- **Library - Chore** From ab040cb25696a900224789cb2f97bbf5193fd307 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 3 Nov 2021 18:55:47 +0000 Subject: [PATCH 021/102] Release 6.9.0 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index b45da21b6..a51875d3a 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.8.3' +__version__ = '6.9.0' From e27a2b1b7c1102710f10fe6674e6b93c64431666 Mon Sep 17 00:00:00 2001 From: hellno Date: Tue, 9 Nov 2021 23:59:21 +0100 Subject: [PATCH 022/102] chore: fix vulnerability in starbank-ecdsa dependency (#1022) Co-authored-by: Jennifer Mah --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 37e68e9d9..04c3b87e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ PyYAML>=4.2b1 python-http-client>=3.2.1 six==1.11.0 pytest==3.8.2 -starkbank-ecdsa>=1.0.0,<2.0.0 +starkbank-ecdsa>=2.0.1 diff --git a/setup.py b/setup.py index 8ec7329c8..365ebb50b 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def getRequires(): deps = [ 'python_http_client>=3.2.1', - 'starkbank-ecdsa>=1.0.0,<2.0.0' + 'starkbank-ecdsa>=2.0.1' ] return deps From 05557b665dd6edfa41e1290c36dfa9fd76be2762 Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Tue, 9 Nov 2021 16:32:32 -0800 Subject: [PATCH 023/102] fix: fix event webhook for updated starbank-ecdsa dependency --- sendgrid/helpers/eventwebhook/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/helpers/eventwebhook/__init__.py b/sendgrid/helpers/eventwebhook/__init__.py index a44eb5b89..c1ec7d1c8 100644 --- a/sendgrid/helpers/eventwebhook/__init__.py +++ b/sendgrid/helpers/eventwebhook/__init__.py @@ -27,7 +27,7 @@ def convert_public_key_to_ecdsa(self, public_key): :return: public key using the ECDSA algorithm :rtype PublicKey """ - return PublicKey.fromPem(public_key) + return PublicKey.fromPem('\n-----BEGIN PUBLIC KEY-----\n'+public_key+'\n-----END PUBLIC KEY-----\n') def verify_signature(self, payload, signature, timestamp, public_key=None): """ From a3cbe32bd270db4fc2d81b92f73baf6ddab113a7 Mon Sep 17 00:00:00 2001 From: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:25:30 -0800 Subject: [PATCH 024/102] Chore: pin more-itertools version --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 04c3b87e8..b2ba4d1be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ python-http-client>=3.2.1 six==1.11.0 pytest==3.8.2 starkbank-ecdsa>=2.0.1 +more-itertools==5.0.0 From f5d6a3837d67d4ed479d4509c14822ad95730291 Mon Sep 17 00:00:00 2001 From: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> Date: Mon, 15 Nov 2021 16:58:16 -0800 Subject: [PATCH 025/102] docs: fix event webhook documentation --- use_cases/email_stats.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/use_cases/email_stats.md b/use_cases/email_stats.md index c40ccb882..10e265721 100644 --- a/use_cases/email_stats.md +++ b/use_cases/email_stats.md @@ -2,4 +2,4 @@ You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](../USAGE.md#stats). -Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as Twilio SendGrid processes your email. \ No newline at end of file +Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://docs.sendgrid.com/for-developers/tracking-events/event) about events that occur as Twilio SendGrid processes your email. From 26009631c6490b2e38f6daf7febe3fe7182699f6 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 17 Nov 2021 19:24:12 +0000 Subject: [PATCH 026/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8004be4db..35318143e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-11-17] Version 6.9.1 +-------------------------- +**Library - Chore** +- [PR #1022](https://github.com/sendgrid/sendgrid-python/pull/1022): fix vulnerability in starbank-ecdsa dependency. Thanks to [@hellno](https://github.com/hellno)! + + [2021-11-03] Version 6.9.0 -------------------------- **Library - Feature** From 1565945d8f9025946ac8a79821ab07444db68e41 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 17 Nov 2021 19:28:16 +0000 Subject: [PATCH 027/102] Release 6.9.1 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index a51875d3a..ae7f14541 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.0' +__version__ = '6.9.1' From 744ca8cf1d7c0ae8fe29c86f18ad89718c99b830 Mon Sep 17 00:00:00 2001 From: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> Date: Wed, 1 Dec 2021 10:36:41 -0800 Subject: [PATCH 028/102] chore: migrate to GitHub Actions (#1027) --- .codeclimate.yml | 3 --- .github/workflows/release.yml | 48 +++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 50 +++++++++++++++++++++++++++++++++++ .travis.yml | 46 -------------------------------- Makefile | 1 + README.md | 3 +-- README.rst | 6 ++--- requirements.txt | 2 +- test/test_project.py | 8 ------ test/test_sendgrid.py | 4 +-- 10 files changed, 106 insertions(+), 65 deletions(-) delete mode 100644 .codeclimate.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index ef7e1cb56..000000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,3 +0,0 @@ -plugins: - pep8: - enabled: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..46df6809d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Publish Python distributions +on: + push: + tags: + - '*' + workflow_dispatch: + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout sendgrid-python + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + + notify-on-failure: + name: Slack notify on failure + if: ${{ failure() }} + needs: [ release ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: 'danger' + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Failed to release {1}{3} {0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id, ':') }} + SLACK_TITLE: Release Failure + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..fe2015a6e --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,50 @@ +name: Run Tests +on: + push: + branches: [ '*' ] + pull_request: + branches: [ main ] + schedule: + # Run automatically at 8AM PST Monday-Friday + - cron: '0 15 * * 1-5' + workflow_dispatch: + +jobs: + tests: + name: Run Tests + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9' ] + steps: + - name: Checkout sendgrid-python + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Build & Test + run: make test-docker test-install + + notify-on-failure: + name: Slack notify on failure + if: ${{ failure() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} + needs: [ tests ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: 'danger' + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Failed running build on {1}{3} {0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id, ':') }} + SLACK_TITLE: Build Failure + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 46f3601b3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -dist: xenial -language: python -cache: pip -services: -- docker -env: - matrix: - - version=2.7 - - version=3.5 - - version=3.6 - - version=3.7 - - version=3.8 - - version=3.9 - global: - - CC_TEST_REPORTER_ID=$TRAVIS_CODE_CLIMATE_TOKEN -before_script: -- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 - > ./cc-test-reporter -- chmod +x ./cc-test-reporter -- "./cc-test-reporter before-build" -script: -- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin; - fi -- make test-docker -after_script: -- make test-install -- ". venv/bin/activate; codecov" -- "./cc-test-reporter after-build --exit-code $?" -deploy: - provider: pypi - user: __token__ - password: "$PYPI_TOKEN" - skip_cleanup: true - distributions: sdist bdist_wheel - on: - tags: true - condition: "$version = 3.6" -notifications: - slack: - if: branch = main - on_pull_requests: false - on_success: never - on_failure: change - rooms: - secure: B0SJHc9Syyf5HOl21abg/Uj/Gp7EusCOly/2JZzUUHCWtxC8C9pWfGf2e674R4vdeJ3FmTKz/1jJZ96vzV0z+XUpT2Fnn6URi4kjI8C0XNTs8la+bz5riSM4TokYOv0HGbL/r0OmHraodCxuX1rpkcYX+FD1dwcGC70eEB6NIu4= diff --git a/Makefile b/Makefile index 620a25993..bb22db4df 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ venv: clean @python --version || (echo "Python is not installed, please install Python 2 or Python 3"; exit 1); + pip install virtualenv virtualenv --python=python venv install: venv diff --git a/README.md b/README.md index 8ce206abb..e2208293d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ![SendGrid Logo](twilio_sendgrid_logo.png) -[![Travis Badge](https://travis-ci.com/sendgrid/sendgrid-python.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-python) -[![codecov](https://img.shields.io/codecov/c/github/sendgrid/sendgrid-python/main.svg?style=flat-square&label=Codecov+Coverage)](https://codecov.io/gh/sendgrid/sendgrid-python) +[![Tests](https://github.com/sendgrid/sendgrid-python/actions/workflows/tests.yml/badge.svg)](https://github.com/sendgrid/sendgrid-python/actions/workflows/tests.yml) [![Docker Badge](https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg)](https://hub.docker.com/r/sendgrid/sendgrid-python/) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) diff --git a/README.rst b/README.rst index a7a076c22..59f693f0f 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ -|Travis Badge| |codecov| |Python Versions| |PyPI Version| |Docker Badge| |Email Notifications Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| +|Tests Badge| |codecov| |Python Versions| |PyPI Version| |Docker Badge| |Email Notifications Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| **This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Python.** @@ -288,8 +288,8 @@ License .. _troubleshooting guide: https://github.com/sendgrid/sendgrid-python/blob/HEAD/TROUBLESHOOTING.md .. _The MIT License (MIT): https://github.com/sendgrid/sendgrid-python/blob/HEAD/LICENSE -.. |Travis Badge| image:: https://travis-ci.com/sendgrid/sendgrid-python.svg?branch=main - :target: https://travis-ci.com/sendgrid/sendgrid-python +.. |Tests Badge| image:: https://github.com/sendgrid/sendgrid-python/actions/workflows/test.yml/badge.svg + :target: https://github.com/sendgrid/sendgrid-python/actions/workflows/test.yml .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/sendgrid.svg :target: https://pypi.org/project/sendgrid/ .. |PyPI Version| image:: https://img.shields.io/pypi/v/sendgrid.svg diff --git a/requirements.txt b/requirements.txt index b2ba4d1be..f4b4ba105 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Flask==1.0.2 +Flask==1.1.2 PyYAML>=4.2b1 python-http-client>=3.2.1 six==1.11.0 diff --git a/test/test_project.py b/test/test_project.py index e30049a3f..c78293dff 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -11,14 +11,6 @@ def test_env(self): def test_gitignore(self): self.assertTrue(os.path.isfile('./.gitignore')) - # ./.travis.yml - def test_travis(self): - self.assertTrue(os.path.isfile('./.travis.yml')) - - # ./.codeclimate.yml - def test_codeclimate(self): - self.assertTrue(os.path.isfile('./.codeclimate.yml')) - # ./CHANGELOG.md def test_changelog(self): self.assertTrue(os.path.isfile('./CHANGELOG.md')) diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index f6177a7d5..0c63851eb 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -1649,14 +1649,14 @@ def test_suppression_invalid_emails__email__delete(self): def test_suppression_spam_report__email__get(self): email = "test_url_param" headers = {'X-Mock': 200} - response = self.sg.client.suppression.spam_report._( + response = self.sg.client.suppression.spam_reports._( email).get(request_headers=headers) self.assertEqual(response.status_code, 200) def test_suppression_spam_report__email__delete(self): email = "test_url_param" headers = {'X-Mock': 204} - response = self.sg.client.suppression.spam_report._( + response = self.sg.client.suppression.spam_reports._( email).delete(request_headers=headers) self.assertEqual(response.status_code, 204) From 807b08bb6dff27e84e454f19f31b2a15a9aa3c9e Mon Sep 17 00:00:00 2001 From: Jennifer Mah Date: Wed, 1 Dec 2021 10:49:09 -0800 Subject: [PATCH 029/102] fix: add Python distribution to release GH action --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 46df6809d..2c59e9075 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,7 @@ jobs: run: | python -m pip install --upgrade pip pip install build + python setup.py sdist bdist_wheel - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 From cec16a4c8941bd778a3c2a432e058d0b7df53dc4 Mon Sep 17 00:00:00 2001 From: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> Date: Wed, 1 Dec 2021 11:21:17 -0800 Subject: [PATCH 030/102] chore: add wheel install for GH action release --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2c59e9075..65ef25a39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,7 @@ jobs: run: | python -m pip install --upgrade pip pip install build + pip install wheel python setup.py sdist bdist_wheel - name: Publish package to PyPI From e00c300aeb3d1031aca96463cab11b4f541c1642 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 1 Dec 2021 21:10:29 +0000 Subject: [PATCH 031/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35318143e..4f102be33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-12-01] Version 6.9.2 +-------------------------- +**Library - Chore** +- [PR #1027](https://github.com/sendgrid/sendgrid-python/pull/1027): migrate to GitHub Actions. Thanks to [@JenniferMah](https://github.com/JenniferMah)! + + [2021-11-17] Version 6.9.1 -------------------------- **Library - Chore** From ed0b3ff73dfcb3b8188199106b7730f7b1d69f16 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 1 Dec 2021 21:13:05 +0000 Subject: [PATCH 032/102] Release 6.9.2 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index ae7f14541..b8fc882cc 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.1' +__version__ = '6.9.2' From 1dcc378bb90ed0d043c9dcfd239eb4c0b5501a81 Mon Sep 17 00:00:00 2001 From: childish-sambino Date: Tue, 14 Dec 2021 09:02:41 -0600 Subject: [PATCH 033/102] test: split up unit and integ tests (#1029) --- Makefile | 3 ++- test/integ/__init__.py | 0 test/{ => integ}/test_sendgrid.py | 0 test/unit/__init__.py | 0 test/{ => unit}/test_app.py | 0 test/{ => unit}/test_config.py | 0 test/{ => unit}/test_email.py | 0 test/{ => unit}/test_eventwebhook.py | 0 test/{ => unit}/test_inbound_send.py | 0 test/{ => unit}/test_mail_helpers.py | 0 test/{ => unit}/test_parse.py | 0 test/{ => unit}/test_project.py | 0 test/{ => unit}/test_spam_check.py | 0 test/{ => unit}/test_stats.py | 0 test/{ => unit}/test_twilio_email.py | 0 test/{ => unit}/test_unassigned.py | 0 16 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/integ/__init__.py rename test/{ => integ}/test_sendgrid.py (100%) create mode 100644 test/unit/__init__.py rename test/{ => unit}/test_app.py (100%) rename test/{ => unit}/test_config.py (100%) rename test/{ => unit}/test_email.py (100%) rename test/{ => unit}/test_eventwebhook.py (100%) rename test/{ => unit}/test_inbound_send.py (100%) rename test/{ => unit}/test_mail_helpers.py (100%) rename test/{ => unit}/test_parse.py (100%) rename test/{ => unit}/test_project.py (100%) rename test/{ => unit}/test_spam_check.py (100%) rename test/{ => unit}/test_stats.py (100%) rename test/{ => unit}/test_twilio_email.py (100%) rename test/{ => unit}/test_unassigned.py (100%) diff --git a/Makefile b/Makefile index bb22db4df..fb61004ce 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,10 @@ test-install: install . venv/bin/activate; pip install -r test/requirements.txt test: test-install + . venv/bin/activate; coverage run -m unittest discover -s test/unit test-integ: test - . venv/bin/activate; coverage run -m unittest discover + . venv/bin/activate; coverage run -m unittest discover -s test/integ version ?= latest test-docker: diff --git a/test/integ/__init__.py b/test/integ/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_sendgrid.py b/test/integ/test_sendgrid.py similarity index 100% rename from test/test_sendgrid.py rename to test/integ/test_sendgrid.py diff --git a/test/unit/__init__.py b/test/unit/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_app.py b/test/unit/test_app.py similarity index 100% rename from test/test_app.py rename to test/unit/test_app.py diff --git a/test/test_config.py b/test/unit/test_config.py similarity index 100% rename from test/test_config.py rename to test/unit/test_config.py diff --git a/test/test_email.py b/test/unit/test_email.py similarity index 100% rename from test/test_email.py rename to test/unit/test_email.py diff --git a/test/test_eventwebhook.py b/test/unit/test_eventwebhook.py similarity index 100% rename from test/test_eventwebhook.py rename to test/unit/test_eventwebhook.py diff --git a/test/test_inbound_send.py b/test/unit/test_inbound_send.py similarity index 100% rename from test/test_inbound_send.py rename to test/unit/test_inbound_send.py diff --git a/test/test_mail_helpers.py b/test/unit/test_mail_helpers.py similarity index 100% rename from test/test_mail_helpers.py rename to test/unit/test_mail_helpers.py diff --git a/test/test_parse.py b/test/unit/test_parse.py similarity index 100% rename from test/test_parse.py rename to test/unit/test_parse.py diff --git a/test/test_project.py b/test/unit/test_project.py similarity index 100% rename from test/test_project.py rename to test/unit/test_project.py diff --git a/test/test_spam_check.py b/test/unit/test_spam_check.py similarity index 100% rename from test/test_spam_check.py rename to test/unit/test_spam_check.py diff --git a/test/test_stats.py b/test/unit/test_stats.py similarity index 100% rename from test/test_stats.py rename to test/unit/test_stats.py diff --git a/test/test_twilio_email.py b/test/unit/test_twilio_email.py similarity index 100% rename from test/test_twilio_email.py rename to test/unit/test_twilio_email.py diff --git a/test/test_unassigned.py b/test/unit/test_unassigned.py similarity index 100% rename from test/test_unassigned.py rename to test/unit/test_unassigned.py From 54fb4035865bee25dea8bbbcd7ea0d9a9fa43235 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 15 Dec 2021 19:39:08 +0000 Subject: [PATCH 034/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f102be33..d4f521a85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-12-15] Version 6.9.3 +-------------------------- +**Library - Test** +- [PR #1029](https://github.com/sendgrid/sendgrid-python/pull/1029): split up unit and integ tests. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + + [2021-12-01] Version 6.9.2 -------------------------- **Library - Chore** From 1c7493cbadaff93a9b1dd918c63b22e129719f17 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 15 Dec 2021 19:41:42 +0000 Subject: [PATCH 035/102] Release 6.9.3 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index b8fc882cc..9d3fb5211 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.2' +__version__ = '6.9.3' From 76c5f46c103533a1c0d8d857e62f3af915cd4a89 Mon Sep 17 00:00:00 2001 From: Jennifer Mah <42650198+JenniferMah@users.noreply.github.com> Date: Wed, 5 Jan 2022 08:27:25 -0700 Subject: [PATCH 036/102] chore: update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e5439a92d..5db04ff6d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2021, Twilio SendGrid, Inc. +Copyright (C) 2022, Twilio SendGrid, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From b729f401dc9c15393cc0e3036a025deff3d711c6 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Wed, 5 Jan 2022 14:48:25 -0800 Subject: [PATCH 037/102] docs: remove leading spaces on error handling example (#1032) --- use_cases/error_handling.md | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/use_cases/error_handling.md b/use_cases/error_handling.md index 187703b60..d0bdf0945 100644 --- a/use_cases/error_handling.md +++ b/use_cases/error_handling.md @@ -6,24 +6,24 @@ Please see [here](https://github.com/sendgrid/python-http-client/blob/HEAD/pytho There are also email specific exceptions located [here](../sendgrid/helpers/mail/exceptions.py) ```python - import os - from sendgrid import SendGridAPIClient - from sendgrid.helpers.mail import (From, To, Subject, PlainTextContent, HtmlContent, Mail) - from python_http_client import exceptions +import os +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import (From, To, Subject, PlainTextContent, HtmlContent, Mail) +from python_http_client import exceptions - sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) - from_email = From("help@twilio.com") - to_email = To("ethomas@twilio.com") - subject = Subject("Sending with Twilio SendGrid is Fun") - plain_text_content = PlainTextContent("and easy to do anywhere, even with Python") - html_content = HtmlContent("and easy to do anywhere, even with Python") - message = Mail(from_email, to_email, subject, plain_text_content, html_content) - try: - response = sendgrid_client.send(message) - print(response.status_code) - print(response.body) - print(response.headers) - except exceptions.BadRequestsError as e: - print(e.body) - exit() +sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) +from_email = From("help@twilio.com") +to_email = To("ethomas@twilio.com") +subject = Subject("Sending with Twilio SendGrid is Fun") +plain_text_content = PlainTextContent("and easy to do anywhere, even with Python") +html_content = HtmlContent("and easy to do anywhere, even with Python") +message = Mail(from_email, to_email, subject, plain_text_content, html_content) +try: + response = sendgrid_client.send(message) + print(response.status_code) + print(response.body) + print(response.headers) +except exceptions.BadRequestsError as e: + print(e.body) + exit() ``` From df13b78b0cdcb410b4516f6761c4d3138edd4b2d Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Sat, 8 Jan 2022 02:49:23 +0530 Subject: [PATCH 038/102] chore: Remove unused import from distutils (#1031) Co-authored-by: Jennifer Mah --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 365ebb50b..e1d6600d6 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ import io import os -from distutils.file_util import copy_file from setuptools import setup, find_packages From ba7135ea3c41785efc1f1177faa3b287a02f721c Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 12 Jan 2022 20:32:31 +0000 Subject: [PATCH 039/102] [Librarian] Version Bump --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f521a85..817ee5611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log All notable changes to this project will be documented in this file. +[2022-01-12] Version 6.9.4 +-------------------------- +**Library - Chore** +- [PR #1031](https://github.com/sendgrid/sendgrid-python/pull/1031): Remove unused import from distutils. Thanks to [@tirkarthi](https://github.com/tirkarthi)! + +**Library - Docs** +- [PR #1032](https://github.com/sendgrid/sendgrid-python/pull/1032): remove leading spaces on error handling example. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + + [2021-12-15] Version 6.9.3 -------------------------- **Library - Test** From dc78d9ebf635d8e5e9d20439d51c6d9f3965b204 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 12 Jan 2022 20:34:59 +0000 Subject: [PATCH 040/102] Release 6.9.4 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 9d3fb5211..55b51e8b2 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.3' +__version__ = '6.9.4' From d7f81db48bdeb6ff14b263604ce3d6036284a232 Mon Sep 17 00:00:00 2001 From: Jack Slingerland Date: Thu, 20 Jan 2022 20:04:47 -0500 Subject: [PATCH 041/102] docs: Removing unused json import (#1036) --- use_cases/transactional_templates.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/use_cases/transactional_templates.md b/use_cases/transactional_templates.md index 9ee4848c3..460fd65ee 100644 --- a/use_cases/transactional_templates.md +++ b/use_cases/transactional_templates.md @@ -28,7 +28,6 @@ I hope you are having a great day in {{ city }} :) ```python import os -import json from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail @@ -86,7 +85,6 @@ I hope you are having a great day in {{{ city }}} :) ```python import os -import json from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import Mail From d742ada8e6aaee77ab2f4f731f7099372255948b Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 26 Jan 2022 19:23:42 +0000 Subject: [PATCH 042/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 817ee5611..5e7d5c0be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2022-01-26] Version 6.9.5 +-------------------------- +**Library - Docs** +- [PR #1036](https://github.com/sendgrid/sendgrid-python/pull/1036): Removing unused json import. Thanks to [@vital101](https://github.com/vital101)! + + [2022-01-12] Version 6.9.4 -------------------------- **Library - Chore** From 3b17a349cc45eeb796d038722cd4a33ed4dea3ed Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 26 Jan 2022 19:26:42 +0000 Subject: [PATCH 043/102] Release 6.9.5 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 55b51e8b2..5b3835adf 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.4' +__version__ = '6.9.5' From bbd1319d5719728de5908b0fc650a5083ed2dcac Mon Sep 17 00:00:00 2001 From: Hunga1 Date: Thu, 3 Feb 2022 13:26:45 -0700 Subject: [PATCH 044/102] chore: merge test and deploy workflows (#1039) --- .github/workflows/release.yml | 50 ------------------- .github/workflows/test-and-deploy.yml | 71 +++++++++++++++++++++++++++ .github/workflows/tests.yml | 50 ------------------- README.md | 2 +- 4 files changed, 72 insertions(+), 101 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test-and-deploy.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 65ef25a39..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Publish Python distributions -on: - push: - tags: - - '*' - workflow_dispatch: - -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Checkout sendgrid-python - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.6' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - pip install wheel - python setup.py sdist bdist_wheel - - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} - - notify-on-failure: - name: Slack notify on failure - if: ${{ failure() }} - needs: [ release ] - runs-on: ubuntu-latest - steps: - - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_COLOR: 'danger' - SLACK_ICON_EMOJI: ':github:' - SLACK_MESSAGE: ${{ format('Failed to release {1}{3} {0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id, ':') }} - SLACK_TITLE: Release Failure - SLACK_USERNAME: GitHub Actions - SLACK_MSG_AUTHOR: twilio-dx - SLACK_FOOTER: Posted automatically using GitHub Actions - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - MSG_MINIMAL: true diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml new file mode 100644 index 000000000..de9233e0a --- /dev/null +++ b/.github/workflows/test-and-deploy.yml @@ -0,0 +1,71 @@ +name: Test and Deploy +on: + push: + branches: [ '*' ] + tags: [ '*' ] + pull_request: + branches: [ main ] + schedule: + # Run automatically at 8AM PST Monday-Friday + - cron: '0 15 * * 1-5' + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9' ] + steps: + - name: Checkout sendgrid-python + uses: actions/checkout@v2 + + - name: Build & Test + run: make test-docker version=${{ matrix.python-version }} + + deploy: + name: Deploy + if: success() && github.ref_type == 'tag' + needs: [ test ] + runs-on: ubuntu-latest + steps: + - name: Checkout sendgrid-python + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + pip install wheel + python setup.py sdist bdist_wheel + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + + notify-on-failure: + name: Slack notify on failure + if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') + needs: [ test, deploy ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: failure + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} + SLACK_TITLE: Action Failure - ${{ github.repository }} + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index fe2015a6e..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Run Tests -on: - push: - branches: [ '*' ] - pull_request: - branches: [ main ] - schedule: - # Run automatically at 8AM PST Monday-Friday - - cron: '0 15 * * 1-5' - workflow_dispatch: - -jobs: - tests: - name: Run Tests - runs-on: ubuntu-latest - timeout-minutes: 20 - strategy: - matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9' ] - steps: - - name: Checkout sendgrid-python - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Build & Test - run: make test-docker test-install - - notify-on-failure: - name: Slack notify on failure - if: ${{ failure() && github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} - needs: [ tests ] - runs-on: ubuntu-latest - steps: - - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_COLOR: 'danger' - SLACK_ICON_EMOJI: ':github:' - SLACK_MESSAGE: ${{ format('Failed running build on {1}{3} {0}/{1}/actions/runs/{2}', github.server_url, github.repository, github.run_id, ':') }} - SLACK_TITLE: Build Failure - SLACK_USERNAME: GitHub Actions - SLACK_MSG_AUTHOR: twilio-dx - SLACK_FOOTER: Posted automatically using GitHub Actions - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - MSG_MINIMAL: true diff --git a/README.md b/README.md index e2208293d..a653e38f9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![SendGrid Logo](twilio_sendgrid_logo.png) -[![Tests](https://github.com/sendgrid/sendgrid-python/actions/workflows/tests.yml/badge.svg)](https://github.com/sendgrid/sendgrid-python/actions/workflows/tests.yml) +[![BuildStatus](https://github.com/sendgrid/sendgrid-python/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/sendgrid-python/actions/workflows/test-and-deploy.yml) [![Docker Badge](https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg)](https://hub.docker.com/r/sendgrid/sendgrid-python/) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) From 0c7a723f0b7c19a5fb5535c2d006d87191f355f9 Mon Sep 17 00:00:00 2001 From: Shwetha Radhakrishna Date: Thu, 3 Feb 2022 16:59:38 -0600 Subject: [PATCH 045/102] chore: add gh release to workflow (#1041) --- .github/workflows/test-and-deploy.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index de9233e0a..f061a5096 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -46,6 +46,13 @@ jobs: pip install wheel python setup.py sdist bdist_wheel + - name: Create GitHub Release + uses: sendgrid/dx-automator/actions/release@main + with: + footer: '**[pypi](https://pypi.org/project/sendgrid/${version})**' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From 412ca9914eec30866a44f1c01f008df3c0a95f28 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Mon, 7 Feb 2022 12:50:41 -0600 Subject: [PATCH 046/102] fix: only do a Docker Login if the secrets are available --- .github/workflows/test-and-deploy.yml | 65 +++++++++++++++------------ 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index f061a5096..7ce3240c7 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -18,46 +18,55 @@ jobs: strategy: matrix: python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9' ] + env: + DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: - name: Checkout sendgrid-python uses: actions/checkout@v2 + - name: Login to Docker Hub + if: env.DOCKER_LOGIN + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_AUTH_TOKEN }} + - name: Build & Test run: make test-docker version=${{ matrix.python-version }} deploy: - name: Deploy - if: success() && github.ref_type == 'tag' - needs: [ test ] - runs-on: ubuntu-latest - steps: - - name: Checkout sendgrid-python - uses: actions/checkout@v2 + name: Deploy + if: success() && github.ref_type == 'tag' + needs: [ test ] + runs-on: ubuntu-latest + steps: + - name: Checkout sendgrid-python + uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.6' + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - pip install wheel - python setup.py sdist bdist_wheel + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build + pip install wheel + python setup.py sdist bdist_wheel - - name: Create GitHub Release - uses: sendgrid/dx-automator/actions/release@main - with: - footer: '**[pypi](https://pypi.org/project/sendgrid/${version})**' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create GitHub Release + uses: sendgrid/dx-automator/actions/release@main + with: + footer: '**[pypi](https://pypi.org/project/sendgrid/${version})**' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} notify-on-failure: name: Slack notify on failure From 807a2c97dcc9fc92764f97c73b6086ab2426c4f5 Mon Sep 17 00:00:00 2001 From: childish-sambino Date: Tue, 8 Feb 2022 09:14:53 -0600 Subject: [PATCH 047/102] chore: upgrade supported language versions (#1043) --- .github/workflows/test-and-deploy.yml | 4 ++-- setup.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 7ce3240c7..842277933 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9' ] + python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10' ] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: @@ -46,7 +46,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.6' + python-version: '3.10' - name: Install dependencies run: | diff --git a/setup.py b/setup.py index e1d6600d6..7e84802f4 100644 --- a/setup.py +++ b/setup.py @@ -38,5 +38,8 @@ def getRequires(): 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ] ) From b85c8fed2ffeff2084d005c164bd13851f245db7 Mon Sep 17 00:00:00 2001 From: childish-sambino Date: Wed, 9 Feb 2022 10:56:42 -0600 Subject: [PATCH 048/102] chore: drop pytest which was not being used (#1044) --- requirements.txt | 1 - test/unit/test_unassigned.py | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index f4b4ba105..0c34aafd4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,5 @@ Flask==1.1.2 PyYAML>=4.2b1 python-http-client>=3.2.1 six==1.11.0 -pytest==3.8.2 starkbank-ecdsa>=2.0.1 more-itertools==5.0.0 diff --git a/test/unit/test_unassigned.py b/test/unit/test_unassigned.py index 6054447d8..08ab943bb 100644 --- a/test/unit/test_unassigned.py +++ b/test/unit/test_unassigned.py @@ -1,9 +1,7 @@ import json -import pytest from sendgrid.helpers.endpoints.ip.unassigned import unassigned - ret_json = '''[ { "ip": "167.89.21.3", "pools": [ @@ -69,8 +67,7 @@ def make_data(): def test_unassigned_ip_json(): - - data = make_data() + data = make_data() as_json = True calculated = unassigned(get_all_ip(), as_json=as_json) @@ -81,8 +78,7 @@ def test_unassigned_ip_json(): def test_unassigned_ip_obj(): - - data = make_data() + data = make_data() as_json = False calculated = unassigned(get_all_ip(), as_json=as_json) From 78615fcd2db479d2d06580fe35739539d68a285a Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Feb 2022 14:49:27 -0800 Subject: [PATCH 049/102] [Librarian] Version Bump --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e7d5c0be..f009359c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log All notable changes to this project will be documented in this file. +[2022-02-09] Version 6.9.6 +-------------------------- +**Library - Chore** +- [PR #1044](https://github.com/sendgrid/sendgrid-python/pull/1044): drop pytest which was not being used. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #1043](https://github.com/sendgrid/sendgrid-python/pull/1043): upgrade supported language versions. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #1041](https://github.com/sendgrid/sendgrid-python/pull/1041): add gh release to workflow. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! +- [PR #1039](https://github.com/sendgrid/sendgrid-python/pull/1039): merge test and deploy workflows. Thanks to [@Hunga1](https://github.com/Hunga1)! + + [2022-01-26] Version 6.9.5 -------------------------- **Library - Docs** From f91a2162add712658b9f5e201f06c51a842cbd0a Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Feb 2022 14:49:28 -0800 Subject: [PATCH 050/102] Release 6.9.6 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 5b3835adf..eea67ac10 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.5' +__version__ = '6.9.6' From 082e3c57c7da4649018b36550f8512c4d99d0fd8 Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Mon, 28 Feb 2022 15:42:42 -0800 Subject: [PATCH 051/102] chore: fix flask dependency test issues (#1050) --- test/requirements.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 6cb2e96d2..17302b22e 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,8 @@ pyyaml -flask +Flask==1.1.4 six coverage codecov mock +itsdangerous==1.1.0 +markupsafe==1.1.1 From 0b774384fb721196b12870d108f7bafe7c8c6b40 Mon Sep 17 00:00:00 2001 From: Elise Shanholtz Date: Tue, 1 Mar 2022 09:53:43 -0800 Subject: [PATCH 052/102] chore: push Datadog Release Metric upon deploy success (#1049) --- .github/workflows/test-and-deploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 842277933..ac0bca0a8 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -68,6 +68,11 @@ jobs: user: __token__ password: ${{ secrets.PYPI_TOKEN }} + - name: Submit metric to Datadog + uses: sendgrid/dx-automator/actions/datadog-release-metric@main + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + notify-on-failure: name: Slack notify on failure if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') From d7d292cf2241c18d052b8e3705dcc134cc0912d5 Mon Sep 17 00:00:00 2001 From: Vinicius Mesel Date: Fri, 4 Mar 2022 18:29:35 -0300 Subject: [PATCH 053/102] chore: Update mail_example.py (#1048) Co-authored-by: Elise Shanholtz --- examples/helpers/mail_example.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/helpers/mail_example.py b/examples/helpers/mail_example.py index 384181501..f6905787b 100644 --- a/examples/helpers/mail_example.py +++ b/examples/helpers/mail_example.py @@ -1,3 +1,6 @@ +import os +import json + from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import * @@ -8,11 +11,7 @@ def build_hello_email(): ## Send a Single Email to a Single Recipient - import os - import json - from sendgrid import SendGridAPIClient - from sendgrid.helpers.mail import Mail, From, To, Subject, PlainTextContent, HtmlContent, SendGridException - + message = Mail(from_email=From('from@example.com', 'Example From Name'), to_emails=To('to@example.com', 'Example To Name'), subject=Subject('Sending with SendGrid is Fun'), @@ -84,11 +83,8 @@ def get_mock_personalization_dict(): return mock_pers def build_multiple_emails_personalized(): - import json - from sendgrid.helpers.mail import Mail, From, To, Cc, Bcc, Subject, PlainTextContent, \ - HtmlContent, SendGridException, Personalization - # Note that the domain for all From email addresses must match + message = Mail(from_email=From('from@example.com', 'Example From Name'), subject=Subject('Sending with SendGrid is Fun'), plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), @@ -117,6 +113,7 @@ def build_multiple_emails_personalized(): def build_attachment1(): """Build attachment mock. Make sure your content is base64 encoded before passing into attachment.content. Another example: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/attachment.md""" + attachment = Attachment() attachment.file_content = ("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNl" "Y3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12") From d1a54500ac460fb9e392701925b1d9f21834581b Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Mar 2022 12:21:55 -0800 Subject: [PATCH 054/102] [Librarian] Version Bump --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f009359c4..a9d8f79db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Change Log All notable changes to this project will be documented in this file. +[2022-03-09] Version 6.9.7 +-------------------------- +**Library - Chore** +- [PR #1048](https://github.com/sendgrid/sendgrid-python/pull/1048): Update mail_example.py. Thanks to [@vmesel](https://github.com/vmesel)! +- [PR #1049](https://github.com/sendgrid/sendgrid-python/pull/1049): push Datadog Release Metric upon deploy success. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #1050](https://github.com/sendgrid/sendgrid-python/pull/1050): fix flask dependency test issues. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + + [2022-02-09] Version 6.9.6 -------------------------- **Library - Chore** From 202fabc99073f1a61302d0e8ecb143e0d45bd8ce Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 9 Mar 2022 12:21:55 -0800 Subject: [PATCH 055/102] Release 6.9.7 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index eea67ac10..59b5dedc7 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.6' +__version__ = '6.9.7' From e3d3ce500ba41f20ed6ce8f0b1a7fcb18882d917 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Thu, 24 Mar 2022 10:48:08 -0500 Subject: [PATCH 056/102] chore: remove outdated announcements --- README.md | 6 +----- README.rst | 10 +--------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a653e38f9..321d86ca3 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-python.svg)](https://github.com/sendgrid/sendgrid-python/graphs/contributors) [![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-python/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-python) -**The default branch name for this repository has been changed to `main` as of 07/27/2020.** - **This library allows you to quickly and easily use the SendGrid Web API v3 via Python.** Version 3.X.X+ of this library provides full support for all SendGrid [Web API v3](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) endpoints, including the new [v3 /mail/send](https://sendgrid.com/blog/introducing-v3mailsend-sendgrids-new-mail-endpoint). @@ -187,9 +185,7 @@ Please see [our helper](sendgrid/helpers/inbound) for utilizing our Inbound Pars # Announcements -Please see our announcement regarding [breaking changes](https://github.com/sendgrid/sendgrid-python/issues/217). Your support is appreciated! - -All updates to this library are documented in our [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases). You may also subscribe to email [release notifications](https://dx.sendgrid.com/newsletter/java) for releases and breaking changes. +All updates to this library are documented in our [CHANGELOG](CHANGELOG.md) and [releases](https://github.com/sendgrid/sendgrid-python/releases). # How to Contribute diff --git a/README.rst b/README.rst index 59f693f0f..93062ba66 100644 --- a/README.rst +++ b/README.rst @@ -3,15 +3,12 @@ -|Tests Badge| |codecov| |Python Versions| |PyPI Version| |Docker Badge| |Email Notifications Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| +|Tests Badge| |codecov| |Python Versions| |PyPI Version| |Docker Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| **This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Python.** **NEW:** -**The default branch name for this repository has been changed to `main` as of 07/27/2020.** - -- Subscribe to email `notifications`_ for releases and breaking changes. - Version 6.X release is a BREAKING CHANGE from version 5.X, please see the `release notes`_ for details. - Send SMS messages with `Twilio`_. @@ -223,7 +220,6 @@ Announcements ============= All updates to this library are documented in our `CHANGELOG`_ and `releases`_. -You may also subscribe to email `release notifications`_ for releases and breaking changes. How to Contribute ================= @@ -253,7 +249,6 @@ License `The MIT License (MIT)`_ -.. _notifications: https://dx.sendgrid.com/newsletter/python .. _Twilio: https://github.com/sendgrid/sendgrid-python/blob/HEAD/use_cases/sms.md .. _release notes: https://github.com/sendgrid/sendgrid-python/releases/tag/v6.0.0 .. _Web API v3: https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html @@ -279,7 +274,6 @@ License .. _breaking changes: https://github.com/sendgrid/sendgrid-python/issues/217 .. _CHANGELOG: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CHANGELOG.md .. _releases: https://github.com/sendgrid/sendgrid-python/releases -.. _release notifications: https://dx.sendgrid.com/newsletter/python .. _CONTRIBUTING: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md .. _Feature Request: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#feature-request .. _Bug Reports: https://github.com/sendgrid/sendgrid-python/blob/HEAD/CONTRIBUTING.md#submit-a-bug-report @@ -298,8 +292,6 @@ License :target: https://codecov.io/gh/sendgrid/sendgrid-python .. |Docker Badge| image:: https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg :target: https://hub.docker.com/r/sendgrid/sendgrid-python/ -.. |Email Notifications Badge| image:: https://dx.sendgrid.com/badge/python - :target: https://dx.sendgrid.com/newsletter/python .. |MIT licensed| image:: https://img.shields.io/badge/license-MIT-blue.svg :target: ./LICENSE .. |Twitter Follow| image:: https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow From 27843fe2d5b7fdf188f606ef20f2beab32b97eee Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Fri, 25 Mar 2022 13:39:50 -0500 Subject: [PATCH 057/102] feat: add PR title validation --- .github/workflows/pr-lint.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/pr-lint.yml diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 000000000..8388f21e8 --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,15 @@ +name: Lint PR +on: + pull_request_target: + types: [ opened, edited, reopened ] + +jobs: + validate: + name: Validate title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v4 + with: + types: chore docs fix feat test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 903c9cb87cf87d018a1d131b4903b4a300b92e0a Mon Sep 17 00:00:00 2001 From: Jonathan Berger Date: Tue, 29 Mar 2022 08:04:42 -0700 Subject: [PATCH 058/102] docs: Fix link that has drifted (#1052) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 321d86ca3..9ffdbb7d0 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ print(response.body) print(response.headers) ``` -The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](examples/helpers/mail_example.py#L16) is an example of how to add it. +The `Mail` constructor creates a [personalization object](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html) for you. [Here](examples/helpers/mail_example.py#L28) is an example of how to add it. ### Without Mail Helper Class From 43c03bdd8baca80a80382bd6445a7c6021d697fa Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Thu, 21 Apr 2022 14:44:33 -0500 Subject: [PATCH 059/102] test: lint PRs on synchronize events Since synchronize events clears the status checks, it needs to be re-run. --- .github/workflows/pr-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 8388f21e8..dc7af3d3c 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -1,7 +1,7 @@ name: Lint PR on: pull_request_target: - types: [ opened, edited, reopened ] + types: [ opened, edited, synchronize, reopened ] jobs: validate: From c798252a31949b9b263f9722294eb94ba3bb1e33 Mon Sep 17 00:00:00 2001 From: "Gareth Paul Jones (GPJ)" Date: Mon, 9 May 2022 10:03:43 -0700 Subject: [PATCH 060/102] docs: Modify README.md in alignment with SendGrid Support (#1055) --- .github/ISSUE_TEMPLATE/config.yml | 10 ---------- ISSUE_TEMPLATE.md | 30 ------------------------------ PULL_REQUEST_TEMPLATE.md | 2 +- README.md | 10 ++++++---- test/unit/test_project.py | 4 ---- 5 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index afcba3446..000000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,10 +0,0 @@ -contact_links: - - name: Twilio SendGrid Support - url: https://support.sendgrid.com - about: Get Support - - name: Stack Overflow - url: https://stackoverflow.com/questions/tagged/sendgrid-python+or+sendgrid+python - about: Ask questions on Stack Overflow - - name: Documentation - url: https://sendgrid.com/docs/for-developers/ - about: View Reference Documentation diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md deleted file mode 100644 index fb2e15cef..000000000 --- a/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,30 +0,0 @@ - - -### Issue Summary -A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, or code examples. - -### Steps to Reproduce -1. This is the first step -2. This is the second step -3. Further steps, etc. - -### Code Snippet -```python -# paste code here -``` - -### Exception/Log -``` -# paste exception/log here -``` - -### Technical details: -* sendgrid-python version: -* python version: - diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index 7c2789ae4..f78ab3918 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -28,4 +28,4 @@ A short description of what this PR does. - [ ] I have added the necessary documentation about the functionality in the appropriate .md file - [ ] I have added inline documentation to the code I modified -If you have questions, please file a [support ticket](https://support.sendgrid.com), or create a GitHub Issue in this repository. +If you have questions, please file a [support ticket](https://support.sendgrid.com). \ No newline at end of file diff --git a/README.md b/README.md index 9ffdbb7d0..663d1e977 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ Version 3.X.X+ of this library provides full support for all SendGrid [Web API v This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-python/issues) and [pull requests](CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests. -Please browse the rest of this README for further detail. +**If you need help using SendGrid, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).** -We appreciate your continued support, thank you! +Please browse the rest of this README for further detail. # Table of Contents @@ -28,6 +28,7 @@ We appreciate your continued support, thank you! * [How to Contribute](#contribute) * [Troubleshooting](#troubleshooting) * [About](#about) +* [Support](#support) * [License](#license) @@ -209,9 +210,10 @@ Please see our [troubleshooting guide](TROUBLESHOOTING.md) for common library is sendgrid-python is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-python are trademarks of Twilio SendGrid, Inc. -If you need help installing or using the library, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com). + +# Support -If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo! +If you need support, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com). # License diff --git a/test/unit/test_project.py b/test/unit/test_project.py index c78293dff..40282bdb7 100644 --- a/test/unit/test_project.py +++ b/test/unit/test_project.py @@ -23,10 +23,6 @@ def test_code_of_conduct(self): def test_contributing(self): self.assertTrue(os.path.isfile('./CONTRIBUTING.md')) - # ./ISSUE_TEMPLATE.md - def test_issue_template(self): - self.assertTrue(os.path.isfile('./ISSUE_TEMPLATE.md')) - # ./LICENSE def test_license(self): self.assertTrue(os.path.isfile('./LICENSE')) From 17a7bcc94f3c02f7cf9327139378d1f5e06cac50 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Thu, 12 May 2022 10:28:26 -0500 Subject: [PATCH 061/102] chore: drop the issue links from FIRST_TIMERS doc --- FIRST_TIMERS.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/FIRST_TIMERS.md b/FIRST_TIMERS.md index 528580c34..a1d563a75 100644 --- a/FIRST_TIMERS.md +++ b/FIRST_TIMERS.md @@ -51,29 +51,3 @@ git push origin ## Important notice Before creating a pull request, make sure that you respect the repository's constraints regarding contributions. You can find them in the [CONTRIBUTING.md](CONTRIBUTING.md) file. - -## Repositories with Open, Easy, Help Wanted, Issue Filters - -* [Python SDK](https://github.com/sendgrid/sendgrid-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [PHP SDK](https://github.com/sendgrid/sendgrid-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [C# SDK](https://github.com/sendgrid/sendgrid-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Ruby SDK](https://github.com/sendgrid/sendgrid-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Node.js SDK](https://github.com/sendgrid/sendgrid-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Java SDK](https://github.com/sendgrid/sendgrid-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Go SDK](https://github.com/sendgrid/sendgrid-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Python SMTPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [PHP SMTPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [C# SMTPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Ruby SMTPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Node.js SMTPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Java SMTPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Go SMTPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Python HTTP Client](https://github.com/sendgrid/python-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [PHP HTTP Client](https://github.com/sendgrid/php-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [C# HTTP Client](https://github.com/sendgrid/csharp-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Java HTTP Client](https://github.com/sendgrid/java-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Ruby HTTP Client](https://github.com/sendgrid/ruby-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Go HTTP Client](https://github.com/sendgrid/rest/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Open API Definition](https://github.com/sendgrid/sendgrid-oai/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [DX Automator](https://github.com/sendgrid/dx-automator/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) -* [Documentation](https://github.com/sendgrid/docs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22) From ef1aa7293e4cda85dcba1cba4524d3e85d8e0281 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Mon, 23 May 2022 11:04:22 -0500 Subject: [PATCH 062/102] docs: drop references to ISSUE_TEMPLATE.md Issues are no longer supported so file was previously removed. --- CONTRIBUTING.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2769176d..890641059 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,9 +2,6 @@ Hello! Thank you for choosing to help contribute to one of the Twilio SendGrid o All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under. -- [Feature Request](#feature-request) -- [Submit a Bug Report](#submit-a-bug-report) - - [Please use our Bug Report Template](#please-use-our-bug-report-template) - [Improvements to the Codebase](#improvements-to-the-codebase) - [Development Environment](#development-environment) - [Prerequisites](#prerequisites) @@ -19,31 +16,6 @@ All third party contributors acknowledge that any contributions they provide wil There are a few ways to contribute, which we'll enumerate below: -## Feature Request - -If you'd like to make a feature request, please read this section. - -The GitHub issue tracker is the preferred channel for library feature requests, but please respect the following restrictions: - -- Please **search for existing issues** in order to ensure we don't have duplicate bugs/feature requests. -- Please be respectful and considerate of others when commenting on issues - -## Submit a Bug Report - -Note: DO NOT include your credentials in ANY code examples, descriptions, or media you make public. - -A software bug is a demonstrable issue in the code base. In order for us to diagnose the issue and respond as quickly as possible, please add as much detail as possible into your bug report. - -Before you decide to create a new issue, please try the following: - -1. Check the GitHub issues tab if the identified issue has already been reported, if so, please add a +1 to the existing post. -2. Update to the latest version of this code and check if the issue has already been fixed -3. Copy and fill in the Bug Report Template we have provided below - -### Please use our Bug Report Template - -In order to make the process easier, we've included a [sample bug report template](ISSUE_TEMPLATE.md). - ## Improvements to the Codebase We welcome direct contributions to the sendgrid-python code base. Thank you! From 653cc47c54d53d401d65d1debb3cdc1d7905b4a1 Mon Sep 17 00:00:00 2001 From: Raghav Katyal Date: Wed, 6 Jul 2022 16:14:12 -0700 Subject: [PATCH 063/102] Adding misc as PR type (#1058) --- .github/workflows/pr-lint.yml | 2 +- PULL_REQUEST_TEMPLATE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index dc7af3d3c..2f5232b08 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -10,6 +10,6 @@ jobs: steps: - uses: amannn/action-semantic-pull-request@v4 with: - types: chore docs fix feat test + types: chore docs fix feat test misc env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index f78ab3918..f9448a3b1 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -3,7 +3,7 @@ We appreciate the effort for this pull request but before that please make sure Please format the PR title appropriately based on the type of change: [!]: -Where is one of: docs, chore, feat, fix, test. +Where is one of: docs, chore, feat, fix, test, misc. Add a '!' after the type for breaking changes (e.g. feat!: new breaking feature). **All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.** From 4288aa618b04a3e99173f59ce43d7a4b379b93c4 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Tue, 3 Jan 2023 09:09:32 -0600 Subject: [PATCH 064/102] docs: updated the year in the license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5db04ff6d..3154774a9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2022, Twilio SendGrid, Inc. +Copyright (C) 2023, Twilio SendGrid, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From 9e8a2599bd86d599465552de591d2ca5413fb101 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 13 Mar 2023 15:46:49 +0100 Subject: [PATCH 065/102] feat: Add Python 3.11 to the testing (#1059) --- .github/workflows/test-and-deploy.yml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index ac0bca0a8..f14974e43 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10' ] + python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11' ] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: diff --git a/setup.py b/setup.py index 7e84802f4..41f11e589 100644 --- a/setup.py +++ b/setup.py @@ -34,12 +34,12 @@ def getRequires(): classifiers=[ 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', ] ) From 93612afeb0114cd98b6efd7c82dbcf98c9a4df27 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 13 Mar 2023 15:57:25 +0100 Subject: [PATCH 066/102] misc: Upgrade GitHub Action pr-lint.yml (#1063) --- .github/workflows/pr-lint.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 2f5232b08..31520079c 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -8,8 +8,14 @@ jobs: name: Validate title runs-on: ubuntu-latest steps: - - uses: amannn/action-semantic-pull-request@v4 + - uses: amannn/action-semantic-pull-request@v5 with: - types: chore docs fix feat test misc + types: | + chore + docs + fix + feat + misc + test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 102842a9dbeb1cabe057ffc0e52603f2dbc44596 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 13 Mar 2023 16:05:34 +0100 Subject: [PATCH 067/102] misc: Upgrade GitHub Action test-and-deploy.yml (#1064) --- .github/workflows/test-and-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index f14974e43..4db532e3d 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -22,11 +22,11 @@ jobs: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: - name: Checkout sendgrid-python - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Login to Docker Hub if: env.DOCKER_LOGIN - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_AUTH_TOKEN }} @@ -41,10 +41,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout sendgrid-python - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.10' From c8076fa684d66ed5c0569feaf7b99dbedd976b77 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 13 Mar 2023 17:11:47 +0100 Subject: [PATCH 068/102] misc: Create GitHub Action to lint Python code (#1065) --- .github/workflows/lint-python.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/lint-python.yml diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml new file mode 100644 index 000000000..1c5f53f23 --- /dev/null +++ b/.github/workflows/lint-python.yml @@ -0,0 +1,16 @@ +# https://beta.ruff.rs +name: ruff +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: pip install --user ruff + - run: ruff --format=github --ignore="E722,F40,F841" --line-length=681 --target-version=py37 . From 4b5c605dda41dbf6dab9ed4ea72ff4014a735885 Mon Sep 17 00:00:00 2001 From: iLan Date: Tue, 21 Mar 2023 11:28:49 -0700 Subject: [PATCH 069/102] feat: Add reply_to_list functionality (#1062) --- sendgrid/helpers/mail/mail.py | 28 ++++++ test/unit/test_mail_helpers.py | 90 +++++++++++++++++++ ..._email_with_multiple_reply_to_addresses.md | 29 ++++++ 3 files changed, 147 insertions(+) create mode 100644 use_cases/send_a_single_email_with_multiple_reply_to_addresses.md diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index ba21f7891..2472ad7d3 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -60,6 +60,7 @@ def __init__( self._ip_pool_name = None self._mail_settings = None self._reply_to = None + self._reply_to_list = None self._send_at = None self._subject = None self._template_id = None @@ -695,6 +696,32 @@ def reply_to(self, value): value = ReplyTo(value[0], value[1]) self._reply_to = value + @property + def reply_to_list(self): + """A list of ReplyTo email addresses + + :rtype: list(ReplyTo), tuple + """ + return self._reply_to_list + + @reply_to_list.setter + def reply_to_list(self, value): + """A list of ReplyTo email addresses + + :param value: A list of ReplyTo email addresses + :type value: list(ReplyTo), tuple + """ + if isinstance(value, list): + for reply in value: + if isinstance(reply, ReplyTo): + if not isinstance(reply.email, str): + raise ValueError('You must provide an email for each entry in a reply_to_list') + else: + raise ValueError( + 'Please use a list of ReplyTos for a reply_to_list.' + ) + self._reply_to_list = value + @property def contents(self): """The contents of the email @@ -981,6 +1008,7 @@ def get(self): 'mail_settings': self._get_or_none(self.mail_settings), 'tracking_settings': self._get_or_none(self.tracking_settings), 'reply_to': self._get_or_none(self.reply_to), + 'reply_to_list': [r.get() for r in self.reply_to_list or []], } return {key: value for key, value in mail.items() diff --git a/test/unit/test_mail_helpers.py b/test/unit/test_mail_helpers.py index a7d08d890..c00307d46 100644 --- a/test/unit/test_mail_helpers.py +++ b/test/unit/test_mail_helpers.py @@ -235,6 +235,58 @@ def test_send_a_single_email_to_multiple_recipients(self): }''') ) + def test_send_a_single_email_with_multiple_reply_to_addresses(self): + from sendgrid.helpers.mail import (Mail, From, ReplyTo, To, Subject, + PlainTextContent, HtmlContent) + self.maxDiff = None + message = Mail( + from_email=From('test+from@example.com', 'Example From Name'), + to_emails=To('test+to0@example.com', 'Example To Name'), + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent('and easy to do anywhere, even with Python'), + html_content=HtmlContent('and easy to do anywhere, even with Python')) + + message.reply_to_list = [ReplyTo(email = 'test+reply_to_1@example.com'), ReplyTo(email = 'test+reply_to_2@example.com')] + + self.assertEqual( + message.get(), + json.loads(r'''{ + "content": [ + { + "type": "text/plain", + "value": "and easy to do anywhere, even with Python" + }, + { + "type": "text/html", + "value": "and easy to do anywhere, even with Python" + } + ], + "from": { + "email": "test+from@example.com", + "name": "Example From Name" + }, + "personalizations": [ + { + "to": [ + { + "email": "test+to0@example.com", + "name": "Example To Name" + } + ] + } + ], + "reply_to_list": [ + { + "email": "test+reply_to_1@example.com" + }, + { + "email": "test+reply_to_2@example.com" + } + ], + "subject": "Sending with SendGrid is Fun" + }''') + ) + def test_multiple_emails_to_multiple_recipients(self): from sendgrid.helpers.mail import (Mail, From, To, Subject, PlainTextContent, HtmlContent, @@ -568,6 +620,44 @@ def test_value_error_is_raised_on_to_emails_set_to_list_of_lists(self): 'and easy to do anywhere, even with Python'), html_content=HtmlContent( 'and easy to do anywhere, even with Python')) + + def test_value_error_is_raised_on_to_emails_set_to_reply_to_list_of_strs(self): + from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) + self.maxDiff = None + to_emails = [ + ('test+to0@example.com', 'Example To Name 0'), + ('test+to1@example.com', 'Example To Name 1') + ] + + mail = Mail( + from_email=From('test+from@example.com', 'Example From Name'), + to_emails=to_emails, + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent( + 'and easy to do anywhere, even with Python'), + html_content=HtmlContent( + 'and easy to do anywhere, even with Python')) + with self.assertRaises(ValueError): + mail.reply_to_list = ['test+reply_to0@example.com', 'test+reply_to1@example.com'] + + def test_value_error_is_raised_on_to_emails_set_to_reply_to_list_of_tuples(self): + from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) + self.maxDiff = None + to_emails = [ + ('test+to0@example.com', 'Example To Name 0'), + ('test+to1@example.com', 'Example To Name 1') + ] + + mail = Mail( + from_email=From('test+from@example.com', 'Example From Name'), + to_emails=to_emails, + subject=Subject('Sending with SendGrid is Fun'), + plain_text_content=PlainTextContent( + 'and easy to do anywhere, even with Python'), + html_content=HtmlContent( + 'and easy to do anywhere, even with Python')) + with self.assertRaises(ValueError): + mail.reply_to_list = [('test+reply_to@example.com', 'Test Name')] def test_error_is_not_raised_on_to_emails_set_to_list_of_tuples(self): from sendgrid.helpers.mail import (PlainTextContent, HtmlContent) diff --git a/use_cases/send_a_single_email_with_multiple_reply_to_addresses.md b/use_cases/send_a_single_email_with_multiple_reply_to_addresses.md new file mode 100644 index 000000000..55d6adf18 --- /dev/null +++ b/use_cases/send_a_single_email_with_multiple_reply_to_addresses.md @@ -0,0 +1,29 @@ +```python +import os +from sendgrid import SendGridAPIClient +from sendgrid.helpers.mail import Mail + +message = Mail( + from_email='from_email@example.com', + to_emails='to@example.com', + subject='Sending with Twilio SendGrid is Fun', + html_content='and easy to do anywhere, even with Python') +message.reply_to_list = [ + ReplyTo( + email='reply-to-1@example.com', + name="Reply To Name 1", + ), + ReplyTo( + email='reply-to-2@example.com', + name="Reply To Name 2", + ) +] +try: + sendgrid_client = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) + response = sendgrid_client.send(message) + print(response.status_code) + print(response.body) + print(response.headers) +except Exception as e: + print(e) +``` From 9fe3e235d06475573b27fb521d31a592799cf8a6 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 22 Mar 2023 11:45:20 -0700 Subject: [PATCH 070/102] [Librarian] Version Bump --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9d8f79db..802270cd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,25 @@ # Change Log All notable changes to this project will be documented in this file. +[2023-03-22] Version 6.10.0 +--------------------------- +**Library - Feature** +- [PR #1062](https://github.com/sendgrid/sendgrid-python/pull/1062): Add reply_to_list functionality. Thanks to [@thepuzzlemaster](https://github.com/thepuzzlemaster)! +- [PR #1059](https://github.com/sendgrid/sendgrid-python/pull/1059): Add Python 3.11 to the testing. Thanks to [@cclauss](https://github.com/cclauss)! + +**Library - Miscellaneous** +- [PR #1065](https://github.com/sendgrid/sendgrid-python/pull/1065): Create GitHub Action to lint Python code. Thanks to [@cclauss](https://github.com/cclauss)! +- [PR #1064](https://github.com/sendgrid/sendgrid-python/pull/1064): Upgrade GitHub Action test-and-deploy.yml. Thanks to [@cclauss](https://github.com/cclauss)! +- [PR #1063](https://github.com/sendgrid/sendgrid-python/pull/1063): Upgrade GitHub Action pr-lint.yml. Thanks to [@cclauss](https://github.com/cclauss)! + +**Library - Test** +- [PR #1058](https://github.com/sendgrid/sendgrid-python/pull/1058): Adding misc as PR type. Thanks to [@rakatyal](https://github.com/rakatyal)! + +**Library - Docs** +- [PR #1055](https://github.com/sendgrid/sendgrid-python/pull/1055): Modify README.md in alignment with SendGrid Support. Thanks to [@garethpaul](https://github.com/garethpaul)! +- [PR #1052](https://github.com/sendgrid/sendgrid-python/pull/1052): Fix link that has drifted. Thanks to [@jonathanberger](https://github.com/jonathanberger)! + + [2022-03-09] Version 6.9.7 -------------------------- **Library - Chore** From 5e9687caf9ed643362220e239b71537ed539c535 Mon Sep 17 00:00:00 2001 From: Twilio Date: Wed, 22 Mar 2023 11:45:21 -0700 Subject: [PATCH 071/102] Release 6.10.0 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 59b5dedc7..466501d04 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.9.7' +__version__ = '6.10.0' From 2fe145956a1ee50355f5da8deab401e1e118c736 Mon Sep 17 00:00:00 2001 From: Seth Ammons Date: Mon, 17 Apr 2023 04:48:43 -0400 Subject: [PATCH 072/102] fix: removing codedev test dependency (#1066) Fix build by removing dead dependency. Per the announcment: https://about.codecov.io/blog/message-regarding-the-pypi-package/ coddev deprecated their pypi package on april 12, 2023 causing the build to break We no longer are registered at codedev: https://app.codecov.io/gh/sendgrid/sendgrid-python "This repo has been deactivated" --- README.rst | 4 +--- test/requirements.txt | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 93062ba66..e23e2300e 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ -|Tests Badge| |codecov| |Python Versions| |PyPI Version| |Docker Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| +|Tests Badge| |Python Versions| |PyPI Version| |Docker Badge| |MIT licensed| |Twitter Follow| |GitHub contributors| |Open Source Helpers| **This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Python.** @@ -288,8 +288,6 @@ License :target: https://pypi.org/project/sendgrid/ .. |PyPI Version| image:: https://img.shields.io/pypi/v/sendgrid.svg :target: https://pypi.org/project/sendgrid/ -.. |codecov| image:: https://img.shields.io/codecov/c/github/sendgrid/sendgrid-python/main.svg?style=flat-square&label=Codecov+Coverage - :target: https://codecov.io/gh/sendgrid/sendgrid-python .. |Docker Badge| image:: https://img.shields.io/docker/automated/sendgrid/sendgrid-python.svg :target: https://hub.docker.com/r/sendgrid/sendgrid-python/ .. |MIT licensed| image:: https://img.shields.io/badge/license-MIT-blue.svg diff --git a/test/requirements.txt b/test/requirements.txt index 17302b22e..859c2456d 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,7 +2,6 @@ pyyaml Flask==1.1.4 six coverage -codecov mock itsdangerous==1.1.0 markupsafe==1.1.1 From bcb4f3379ec07f8d337d7aaa63d461259ec5ee41 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 14 Nov 2023 15:44:25 +0530 Subject: [PATCH 073/102] feat: geolocation setter in sendgrid-python for GDPR compliance --- .github/workflows/lint-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index 1c5f53f23..ba064864c 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v3 - run: pip install --user ruff - - run: ruff --format=github --ignore="E722,F40,F841" --line-length=681 --target-version=py37 . + - run: ruff --format=github --ignore="E722,F40,F841" --line-length=320 --target-version=py37 . From d3ddc8aa27707ec5e2b13a65dfa4c1e2bc837497 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 14 Nov 2023 15:46:52 +0530 Subject: [PATCH 074/102] revert changes --- .github/workflows/lint-python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index ba064864c..1c5f53f23 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v3 - run: pip install --user ruff - - run: ruff --format=github --ignore="E722,F40,F841" --line-length=320 --target-version=py37 . + - run: ruff --format=github --ignore="E722,F40,F841" --line-length=681 --target-version=py37 . From b5afcca6c2c4b29330f81f92b79bf2526645223a Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Fri, 24 Nov 2023 00:29:36 +0530 Subject: [PATCH 075/102] feat: geolocation setter in sendgrid-python for GDPR compliance (#1073) --- .github/workflows/lint-python.yml | 2 +- examples/dataresidency/set_region.py | 37 ++++++++++++++++++++++++++++ sendgrid/base_interface.py | 23 ++++++++++++++++- test/unit/test_sendgrid.py | 27 ++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 examples/dataresidency/set_region.py create mode 100644 test/unit/test_sendgrid.py diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index 1c5f53f23..ace47f77d 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v3 - run: pip install --user ruff - - run: ruff --format=github --ignore="E722,F40,F841" --line-length=681 --target-version=py37 . + - run: ruff --ignore="E722,F40,F841" --line-length=320 --target-version=py37 . diff --git a/examples/dataresidency/set_region.py b/examples/dataresidency/set_region.py new file mode 100644 index 000000000..9aae2611f --- /dev/null +++ b/examples/dataresidency/set_region.py @@ -0,0 +1,37 @@ +import sendgrid +import os + +from sendgrid import Email, To, Content, Mail + +# Example 1 +# setting region to be "global" + +sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY')) +from_email = Email("example@abc.com") +to_email = To("example@abc.com") +subject = "Sending with SendGrid is Fun" +content = Content("text/plain", "and easy to do anywhere, even with Python") +mail = Mail(from_email, to_email, subject, content) +sg.set_sendgrid_data_residency("global") +print(sg.client.host) +response = sg.client.mail.send.post(request_body=mail.get()) +print(response) +print(response.status_code) +print(response.body) +print(response.headers) + +# Example 2 +# setting region to "eu" +sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY_EU')) +sg.set_sendgrid_data_residency("eu") +from_email = Email("example@abc.com") +to_email = To("example@abc.com") +subject = "Sending with SendGrid is Fun" +content = Content("text/plain", "and easy to do anywhere, even with Python") +print(sg.client.host) +mail = Mail(from_email, to_email, subject, content) +response = sg.client.mail.send.post(request_body=mail.get()) +print(response) +print(response.status_code) +print(response.body) +print(response.headers) \ No newline at end of file diff --git a/sendgrid/base_interface.py b/sendgrid/base_interface.py index 92b38247e..f94f09479 100644 --- a/sendgrid/base_interface.py +++ b/sendgrid/base_interface.py @@ -1,5 +1,6 @@ import python_http_client +region_host_dict = {'eu':'https://api.eu.sendgrid.com','global':'https://api.sendgrid.com'} class BaseInterface(object): def __init__(self, auth, host, impersonate_subuser): @@ -22,10 +23,10 @@ def __init__(self, auth, host, impersonate_subuser): """ from . import __version__ self.auth = auth - self.host = host self.impersonate_subuser = impersonate_subuser self.version = __version__ self.useragent = 'sendgrid/{};python'.format(self.version) + self.host = host self.client = python_http_client.Client( host=self.host, @@ -60,3 +61,23 @@ def send(self, message): message = message.get() return self.client.mail.send.post(request_body=message) + + def set_sendgrid_data_residency(self, region): + """ + Client libraries contain setters for specifying region/edge. + This supports global and eu regions only. This set will likely expand in the future. + Global is the default residency (or region) + Global region means the message will be sent through https://api.sendgrid.com + EU region means the message will be sent through https://api.eu.sendgrid.com + :param region: string + :return: + """ + if region in region_host_dict.keys(): + self.host = region_host_dict[region] + if self._default_headers is not None: + self.client = python_http_client.Client( + host=self.host, + request_headers=self._default_headers, + version=3) + else: + raise ValueError("region can only be \"eu\" or \"global\"") diff --git a/test/unit/test_sendgrid.py b/test/unit/test_sendgrid.py new file mode 100644 index 000000000..328d978ab --- /dev/null +++ b/test/unit/test_sendgrid.py @@ -0,0 +1,27 @@ +import unittest +import sendgrid + +class UnitTests(unittest.TestCase): + def test_host_with_no_region(self): + sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY') + self.assertEqual("https://api.sendgrid.com",sg.client.host) + + def test_host_with_eu_region(self): + sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY') + sg.set_sendgrid_data_residency("eu") + self.assertEqual("https://api.eu.sendgrid.com",sg.client.host) + + def test_host_with_global_region(self): + sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY') + sg.set_sendgrid_data_residency("global") + self.assertEqual("https://api.sendgrid.com",sg.client.host) + + def test_with_region_is_none(self): + sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY') + with self.assertRaises(ValueError): + sg.set_sendgrid_data_residency(None) + + def test_with_region_is_invalid(self): + sg = sendgrid.SendGridAPIClient(api_key='MY_API_KEY') + with self.assertRaises(ValueError): + sg.set_sendgrid_data_residency("abc") \ No newline at end of file From 4804d32b17e9d396e319c1943792537dc1846008 Mon Sep 17 00:00:00 2001 From: Twilio Date: Fri, 1 Dec 2023 05:16:21 +0000 Subject: [PATCH 076/102] [Librarian] Version Bump --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 802270cd8..4415a03f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log All notable changes to this project will be documented in this file. +[2023-12-01] Version 6.11.0 +--------------------------- +**Library - Feature** +- [PR #1073](https://github.com/sendgrid/sendgrid-python/pull/1073): geolocation setter in sendgrid-python for GDPR compliance. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Library - Test** +- [PR #1066](https://github.com/sendgrid/sendgrid-python/pull/1066): removing codedev test dependency. Thanks to [@sethgrid](https://github.com/sethgrid)! + + [2023-03-22] Version 6.10.0 --------------------------- **Library - Feature** From 4e4ac47e61f52b9ead5020f807f4eb151f9a0bc6 Mon Sep 17 00:00:00 2001 From: Twilio Date: Fri, 1 Dec 2023 05:16:22 +0000 Subject: [PATCH 077/102] Release 6.11.0 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 466501d04..901082d42 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.10.0' +__version__ = '6.11.0' From 78acb96d25a299ad862396c1fbc399c897998bfd Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 26 Dec 2023 13:53:33 +0530 Subject: [PATCH 078/102] chore: commit to main to check if the commits go directly into main. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 663d1e977..d41c0a1c4 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ response = sg.client.mail.send.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) + ``` ## General v3 Web API Usage (With [Fluent Interface](https://sendgrid.com/blog/using-python-to-implement-a-fluent-interface-to-any-rest-api/)) From 9515dce6c8229c9cf7272701d0c2664c05727f16 Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Tue, 26 Dec 2023 13:54:42 +0530 Subject: [PATCH 079/102] chore: rolling back direct commits --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d41c0a1c4..663d1e977 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,6 @@ response = sg.client.mail.send.post(request_body=data) print(response.status_code) print(response.body) print(response.headers) - ``` ## General v3 Web API Usage (With [Fluent Interface](https://sendgrid.com/blog/using-python-to-implement-a-fluent-interface-to-any-rest-api/)) From e2a2cfd7c0632ead3ecdeb725ec4798b711a7931 Mon Sep 17 00:00:00 2001 From: Shubham Date: Fri, 11 Apr 2025 15:00:51 +0530 Subject: [PATCH 080/102] chore: install docker-compose (#1099) * chore: install docker-compose * chore: update licence year * chore: fix lint-python --- .github/workflows/lint-python.yml | 2 +- .github/workflows/test-and-deploy.yml | 5 +++++ LICENSE | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index ace47f77d..5dcf0328c 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: actions/checkout@v3 - run: pip install --user ruff - - run: ruff --ignore="E722,F40,F841" --line-length=320 --target-version=py37 . + - run: ruff check --ignore="E722,F40,F841" --line-length=320 --target-version=py37 . diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 4db532e3d..25408ac0a 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -31,6 +31,11 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_AUTH_TOKEN }} + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + - name: Build & Test run: make test-docker version=${{ matrix.python-version }} diff --git a/LICENSE b/LICENSE index 3154774a9..126ceb1a3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2023, Twilio SendGrid, Inc. +Copyright (C) 2025, Twilio SendGrid, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From ee54d81051d45b0a667642866b74dc7efbc7155b Mon Sep 17 00:00:00 2001 From: Meysam Date: Tue, 15 Apr 2025 22:05:45 +0700 Subject: [PATCH 081/102] feat: add support for python3.12 and 3.13 (#1087) --- .github/workflows/test-and-deploy.yml | 2 +- Makefile | 6 ++--- setup.py | 2 ++ test/requirements.txt | 1 + tox.ini | 32 ++++++++++++++++++++++++++- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 25408ac0a..ba8b69905 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11' ] + python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' , '3.13'] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: diff --git a/Makefile b/Makefile index fb61004ce..96161106d 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,11 @@ venv: clean virtualenv --python=python venv install: venv + . venv/bin/activate; pip install -r test/requirements.txt . venv/bin/activate; python setup.py install . venv/bin/activate; pip install -r requirements.txt -test-install: install - . venv/bin/activate; pip install -r test/requirements.txt - -test: test-install +test: install . venv/bin/activate; coverage run -m unittest discover -s test/unit test-integ: test diff --git a/setup.py b/setup.py index 41f11e589..7c797ae67 100644 --- a/setup.py +++ b/setup.py @@ -41,5 +41,7 @@ def getRequires(): 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', ] ) diff --git a/test/requirements.txt b/test/requirements.txt index 859c2456d..40552deba 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -5,3 +5,4 @@ coverage mock itsdangerous==1.1.0 markupsafe==1.1.1 +setuptools diff --git a/tox.ini b/tox.ini index 926a3c9dd..8f4f2db9a 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py27, py34, py35, py36, py37 +envlist = py27, py34, py35, py36, py37, py38, py39, py310, py311, py312, py313 [testenv] commands = coverage erase @@ -39,3 +39,33 @@ basepython = python3.6 commands = {[testenv]commands} deps = {[testenv]deps} basepython = python3.7 + +[testenv:py38] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.8 + +[testenv:py39] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.9 + +[testenv:py310] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.10 + +[testenv:py311] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.11 + +[testenv:py312] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.12 + +[testenv:py313] +commands = {[testenv]commands} +deps = {[testenv]deps} +basepython = python3.13 From 09bc8466ddf1ecd11a6dc7ebb7a8338fb5afca86 Mon Sep 17 00:00:00 2001 From: GPK Date: Fri, 25 Apr 2025 14:06:33 +0100 Subject: [PATCH 082/102] chore: Add werkzeug package to setup file (#1098) * Add werkzeug package to setup file * Add werkzeug package to setup file * Update versions * Remove EOL python versions --------- Co-authored-by: Shubham --- .github/workflows/test-and-deploy.yml | 2 +- setup.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index ba8b69905..959970d94 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -17,7 +17,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12' , '3.13'] + python-version: [ '3.9', '3.10', '3.11', '3.12' , '3.13'] env: DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} steps: diff --git a/setup.py b/setup.py index 7c797ae67..0753e3997 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,11 @@ def getRequires(): deps = [ 'python_http_client>=3.2.1', - 'starkbank-ecdsa>=2.0.1' + 'starkbank-ecdsa>=2.0.1', + "werkzeug>=0.11.15,<1.0.0 ; python_version < '3.0'", + "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.6'", + "werkzeug>=2.0.0,<3.0.0 ; python_version >= '3.6' and python_version < '3.11'", + "werkzeug>=3.0.0 ; python_version >= '3.11'" ] return deps From ac693fe02295e5e0b77070bab6fa460c697f8997 Mon Sep 17 00:00:00 2001 From: Twilio Date: Mon, 5 May 2025 10:35:35 +0000 Subject: [PATCH 083/102] [Librarian] Version Bump --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4415a03f7..a2215795b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-05-05] Version 6.12.0 +--------------------------- +**Library - Chore** +- [PR #1098](https://github.com/sendgrid/sendgrid-python/pull/1098): Add werkzeug package to setup file. Thanks to [@gopidesupavan](https://github.com/gopidesupavan)! +- [PR #1099](https://github.com/sendgrid/sendgrid-python/pull/1099): install docker-compose. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Library - Feature** +- [PR #1087](https://github.com/sendgrid/sendgrid-python/pull/1087): add support for python3.12 and 3.13. Thanks to [@meysam81](https://github.com/meysam81)! + + [2023-12-01] Version 6.11.0 --------------------------- **Library - Feature** From 774663f5a0af011d23908d0dbd932cb64ee96d70 Mon Sep 17 00:00:00 2001 From: Twilio Date: Mon, 5 May 2025 10:35:35 +0000 Subject: [PATCH 084/102] Release 6.12.0 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 901082d42..142f2122e 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.11.0' +__version__ = '6.12.0' From 6eb4375f4d1ef1e0c1ad17d07858706291380ebc Mon Sep 17 00:00:00 2001 From: ranjanprasad1996 <141220652+ranjanprasad1996@users.noreply.github.com> Date: Fri, 9 May 2025 20:54:52 +0530 Subject: [PATCH 085/102] fix: Vulnerability fix for starkbank-ecdsa 2.2.0 dependency (#1085) * Updated webhook helper to use a different edcsa library * chore: dummy commit * Update dependencies --------- Co-authored-by: Shubham --- requirements.txt | 6 ++--- sendgrid/helpers/eventwebhook/__init__.py | 30 +++++++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0c34aafd4..c95204480 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -Flask==1.1.2 +Flask==3.1.0 PyYAML>=4.2b1 python-http-client>=3.2.1 -six==1.11.0 -starkbank-ecdsa>=2.0.1 +six==1.17.0 +ecdsa>=0.19.1,<1 more-itertools==5.0.0 diff --git a/sendgrid/helpers/eventwebhook/__init__.py b/sendgrid/helpers/eventwebhook/__init__.py index c1ec7d1c8..d97604df8 100644 --- a/sendgrid/helpers/eventwebhook/__init__.py +++ b/sendgrid/helpers/eventwebhook/__init__.py @@ -1,8 +1,7 @@ -from ellipticcurve.ecdsa import Ecdsa -from ellipticcurve.publicKey import PublicKey -from ellipticcurve.signature import Signature - -from .eventwebhook_header import EventWebhookHeader +from ecdsa import VerifyingKey, BadSignatureError +from ecdsa.util import sigdecode_der +import base64 +import hashlib class EventWebhook: """ @@ -20,14 +19,15 @@ def __init__(self, public_key=None): def convert_public_key_to_ecdsa(self, public_key): """ - Convert the public key string to a ECPublicKey. + Convert the public key string to a VerifyingKey object. :param public_key: verification key under Mail Settings :type public_key string - :return: public key using the ECDSA algorithm - :rtype PublicKey + :return: VerifyingKey object using the ECDSA algorithm + :rtype VerifyingKey """ - return PublicKey.fromPem('\n-----BEGIN PUBLIC KEY-----\n'+public_key+'\n-----END PUBLIC KEY-----\n') + pem_key = "-----BEGIN PUBLIC KEY-----\n" + public_key + "\n-----END PUBLIC KEY-----" + return VerifyingKey.from_pem(pem_key) def verify_signature(self, payload, signature, timestamp, public_key=None): """ @@ -40,11 +40,15 @@ def verify_signature(self, payload, signature, timestamp, public_key=None): :param timestamp: value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header :type timestamp: string :param public_key: elliptic curve public key - :type public_key: PublicKey + :type public_key: VerifyingKey :return: true or false if signature is valid """ - timestamped_payload = timestamp + payload - decoded_signature = Signature.fromBase64(signature) + timestamped_payload = (timestamp + payload).encode('utf-8') + decoded_signature = base64.b64decode(signature) key = public_key or self.public_key - return Ecdsa.verify(timestamped_payload, decoded_signature, key) + try: + key.verify(decoded_signature, timestamped_payload, hashfunc=hashlib.sha256, sigdecode=sigdecode_der) + return True + except BadSignatureError: + return False From 096719d8daf5846664eb3f6b4649c826176a959c Mon Sep 17 00:00:00 2001 From: Twilio Date: Tue, 13 May 2025 09:44:12 +0000 Subject: [PATCH 086/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2215795b..2936c9a18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-05-13] Version 6.12.1 +--------------------------- +**Library - Fix** +- [PR #1085](https://github.com/sendgrid/sendgrid-python/pull/1085): Vulnerability fix for starkbank-ecdsa 2.2.0 dependency. Thanks to [@ranjanprasad1996](https://github.com/ranjanprasad1996)! + + [2025-05-05] Version 6.12.0 --------------------------- **Library - Chore** From 2acb010ae303cca78d696b82b739809b7f319187 Mon Sep 17 00:00:00 2001 From: Twilio Date: Tue, 13 May 2025 09:44:12 +0000 Subject: [PATCH 087/102] Release 6.12.1 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 142f2122e..431e91f2e 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.12.0' +__version__ = '6.12.1' From e1ed323bb0a595b7488fbb0c8d8351682ff97f55 Mon Sep 17 00:00:00 2001 From: Shubham Date: Tue, 13 May 2025 16:19:25 +0530 Subject: [PATCH 088/102] chore: update ecdsa in setup.py (#1102) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0753e3997..b3a8e5c86 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def getRequires(): deps = [ 'python_http_client>=3.2.1', - 'starkbank-ecdsa>=2.0.1', + 'ecdsa>=0.19.1,<1', "werkzeug>=0.11.15,<1.0.0 ; python_version < '3.0'", "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.6'", "werkzeug>=2.0.0,<3.0.0 ; python_version >= '3.6' and python_version < '3.11'", From a1acbf3a53e5f5b122614718acbdc6a7196921a9 Mon Sep 17 00:00:00 2001 From: Twilio Date: Tue, 13 May 2025 10:51:11 +0000 Subject: [PATCH 089/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2936c9a18..607b465c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-05-13] Version 6.12.2 +--------------------------- +**Library - Chore** +- [PR #1102](https://github.com/sendgrid/sendgrid-python/pull/1102): update ecdsa in setup.py. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + + [2025-05-13] Version 6.12.1 --------------------------- **Library - Fix** From 3f25a2a6ed33878e13cfe8d76d283b1d6c7b380a Mon Sep 17 00:00:00 2001 From: Twilio Date: Tue, 13 May 2025 10:51:12 +0000 Subject: [PATCH 090/102] Release 6.12.2 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 431e91f2e..67234a38e 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.12.1' +__version__ = '6.12.2' From a78bd11b854ab38978f73c7e3fda98110bd9f840 Mon Sep 17 00:00:00 2001 From: Elad Kalif <45845474+eladkal@users.noreply.github.com> Date: Wed, 14 May 2025 11:02:30 +0300 Subject: [PATCH 091/102] chore: Relax werkzeug version (#1103) --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b3a8e5c86..a1b1a9743 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,11 @@ def getRequires(): 'ecdsa>=0.19.1,<1', "werkzeug>=0.11.15,<1.0.0 ; python_version < '3.0'", "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.6'", - "werkzeug>=2.0.0,<3.0.0 ; python_version >= '3.6' and python_version < '3.11'", - "werkzeug>=3.0.0 ; python_version >= '3.11'" + "werkzeug>=0.15.0,<2.3.0 ; python_version >= '3.0' and python_version < '3.7'", + "werkzeug>=0.16.0,<3.1.0 ; python_version >= '3.0' and python_version < '3.8'", + "werkzeug>=1.0.0 ; python_version >= '3.9'", + "werkzeug>=2.2.0 ; python_version >= '3.11'", + "werkzeug>=2.3.5 ; python_version >= '3.12'" ] return deps From 4671192ce266f575eca28c062766ff4194d66ae9 Mon Sep 17 00:00:00 2001 From: Elad Kalif <45845474+eladkal@users.noreply.github.com> Date: Wed, 14 May 2025 17:35:46 +0300 Subject: [PATCH 092/102] chore: fix werkzeug lower versions (#1104) --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index a1b1a9743..745edea81 100644 --- a/setup.py +++ b/setup.py @@ -12,9 +12,9 @@ def getRequires(): 'python_http_client>=3.2.1', 'ecdsa>=0.19.1,<1', "werkzeug>=0.11.15,<1.0.0 ; python_version < '3.0'", - "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.6'", - "werkzeug>=0.15.0,<2.3.0 ; python_version >= '3.0' and python_version < '3.7'", - "werkzeug>=0.16.0,<3.1.0 ; python_version >= '3.0' and python_version < '3.8'", + "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.7'", + "werkzeug>=0.15.0,<2.3.0 ; python_version >= '3.0' and python_version < '3.8'", # version 2.3.0 dropped support for Python 3.7 + "werkzeug>=0.16.0,<3.1.0 ; python_version >= '3.0' and python_version < '3.9'", # version 3.1.0 dropped support for Python 3.8 "werkzeug>=1.0.0 ; python_version >= '3.9'", "werkzeug>=2.2.0 ; python_version >= '3.11'", "werkzeug>=2.3.5 ; python_version >= '3.12'" From 3e9d4efac5d652de81fb82ae38d256aad78c00d5 Mon Sep 17 00:00:00 2001 From: Shubham Date: Fri, 23 May 2025 11:51:29 +0530 Subject: [PATCH 093/102] chore: export EventWebhookHeader (#1107) --- sendgrid/helpers/eventwebhook/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sendgrid/helpers/eventwebhook/__init__.py b/sendgrid/helpers/eventwebhook/__init__.py index d97604df8..82a2cd6b8 100644 --- a/sendgrid/helpers/eventwebhook/__init__.py +++ b/sendgrid/helpers/eventwebhook/__init__.py @@ -2,6 +2,7 @@ from ecdsa.util import sigdecode_der import base64 import hashlib +from .eventwebhook_header import EventWebhookHeader class EventWebhook: """ From a24ab9de13b2b182985860e5979b1368d2e9fa95 Mon Sep 17 00:00:00 2001 From: Twilio Date: Thu, 29 May 2025 12:11:32 +0000 Subject: [PATCH 094/102] [Librarian] Version Bump --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 607b465c5..7a69e3f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-05-29] Version 6.12.3 +--------------------------- +**Library - Chore** +- [PR #1107](https://github.com/sendgrid/sendgrid-python/pull/1107): export EventWebhookHeader. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! +- [PR #1104](https://github.com/sendgrid/sendgrid-python/pull/1104): fix werkzeug lower versions. Thanks to [@eladkal](https://github.com/eladkal)! +- [PR #1103](https://github.com/sendgrid/sendgrid-python/pull/1103): Relax werkzeug version. Thanks to [@eladkal](https://github.com/eladkal)! + + [2025-05-13] Version 6.12.2 --------------------------- **Library - Chore** From 159f5dd2d4a6eb360ca61356b009b37fcc6aa5c8 Mon Sep 17 00:00:00 2001 From: Twilio Date: Thu, 29 May 2025 12:11:32 +0000 Subject: [PATCH 095/102] Release 6.12.3 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 67234a38e..67ae80f96 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.12.2' +__version__ = '6.12.3' From f5bf6153b5dabf6fe307a8acdb0e59ce17a0c07a Mon Sep 17 00:00:00 2001 From: Manisha Singh Date: Mon, 2 Jun 2025 16:40:55 +0530 Subject: [PATCH 096/102] chore: bug-fix (#1109) --- sendgrid/helpers/mail/mail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/helpers/mail/mail.py b/sendgrid/helpers/mail/mail.py index 2472ad7d3..e475fe764 100644 --- a/sendgrid/helpers/mail/mail.py +++ b/sendgrid/helpers/mail/mail.py @@ -567,7 +567,7 @@ def add_custom_arg(self, custom_arg): :param value: A CustomArg object or a dict of custom arg key/values :type value: CustomArg, dict """ - if custom_arg.personalization is not None: + if not isinstance(custom_arg, dict) and custom_arg.personalization is not None: try: personalization = \ self._personalizations[custom_arg.personalization] From 59994bfafc59fbe7fa2bb9338654e5e6a4e4f612 Mon Sep 17 00:00:00 2001 From: Twilio Date: Thu, 12 Jun 2025 10:27:17 +0000 Subject: [PATCH 097/102] [Librarian] Version Bump --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a69e3f92..87dde6650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-06-12] Version 6.12.4 +--------------------------- +**Library - Chore** +- [PR #1109](https://github.com/sendgrid/sendgrid-python/pull/1109): bug-fix. Thanks to [@manisha1997](https://github.com/manisha1997)! + + [2025-05-29] Version 6.12.3 --------------------------- **Library - Chore** From 7eafe1854f42ef2d6863a7288c1c2e73f9aa5c82 Mon Sep 17 00:00:00 2001 From: Twilio Date: Thu, 12 Jun 2025 10:27:18 +0000 Subject: [PATCH 098/102] Release 6.12.4 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 67ae80f96..127e2ed69 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.12.3' +__version__ = '6.12.4' From af2c4e70b338cdf4ccca4ed12184fdda5926dcc6 Mon Sep 17 00:00:00 2001 From: Shubham Date: Thu, 11 Sep 2025 13:20:25 +0530 Subject: [PATCH 099/102] chore: use make-test instead of make test-docker (#1117) --- .github/workflows/test-and-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 959970d94..98bbeefbd 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -37,7 +37,7 @@ jobs: sudo apt-get install -y docker-compose - name: Build & Test - run: make test-docker version=${{ matrix.python-version }} + run: make test deploy: name: Deploy From 68288529c5e510e6fe535c42d7e52fea5922558a Mon Sep 17 00:00:00 2001 From: David Acevedo Date: Thu, 11 Sep 2025 02:57:07 -0500 Subject: [PATCH 100/102] fix: #1108 - Replace ecdsa with cryptography (#1114) Co-authored-by: Shubham --- CONTRIBUTING.md | 2 +- README.md | 2 +- README.rst | 4 ++-- requirements.txt | 2 +- sendgrid/helpers/eventwebhook/__init__.py | 21 +++++++++++---------- setup.py | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 890641059..af9507154 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,7 @@ We welcome direct contributions to the sendgrid-python code base. Thank you! - Python version 2.7, 3.5, 3.6, 3.7, or 3.8 - [python_http_client](https://github.com/sendgrid/python-http-client) -- [ecdsa_python](https://github.com/starkbank/ecdsa-python) +- [cryptography](https://github.com/pyca/cryptography) - [pyenv](https://github.com/yyuu/pyenv) - [tox](https://pypi.python.org/pypi/tox) diff --git a/README.md b/README.md index 663d1e977..b1b36686f 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ pip install sendgrid ## Dependencies - [Python-HTTP-Client](https://github.com/sendgrid/python-http-client) -- [ECDSA-Python](https://github.com/starkbank/ecdsa-python) +- [Cryptography](https://github.com/pyca/cryptography) diff --git a/README.rst b/README.rst index e23e2300e..526c4ca40 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ Dependencies ------------ - `Python-HTTP-Client`_ -- `ECDSA-Python`_ +- `Cryptography`_ Quick Start =========== @@ -259,7 +259,7 @@ License .. _Twilio account: https://www.twilio.com/try-twilio?source=sendgrid-python .. _SENDGRID_API_KEY: https://app.sendgrid.com/settings/api_keys .. _Python-HTTP-Client: https://github.com/sendgrid/python-http-client -.. _ECDSA-Python: https://github.com/starkbank/ecdsa-python +.. _Cryptography: https://github.com/pyca/cryptography .. _/mail/send Helper: https://github.com/sendgrid/sendgrid-python/tree/HEAD/sendgrid/helpers/mail .. _personalization object: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html .. _Fluent Interface: https://sendgrid.com/blog/using-python-to-implement-a-fluent-interface-to-any-rest-api/ diff --git a/requirements.txt b/requirements.txt index c95204480..ed2594a90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,5 @@ Flask==3.1.0 PyYAML>=4.2b1 python-http-client>=3.2.1 six==1.17.0 -ecdsa>=0.19.1,<1 +cryptography>=45.0.6 more-itertools==5.0.0 diff --git a/sendgrid/helpers/eventwebhook/__init__.py b/sendgrid/helpers/eventwebhook/__init__.py index 82a2cd6b8..9d618bf3a 100644 --- a/sendgrid/helpers/eventwebhook/__init__.py +++ b/sendgrid/helpers/eventwebhook/__init__.py @@ -1,7 +1,8 @@ -from ecdsa import VerifyingKey, BadSignatureError -from ecdsa.util import sigdecode_der +from cryptography.exceptions import InvalidSignature +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.asymmetric import ec +from cryptography.hazmat.primitives.serialization import load_pem_public_key import base64 -import hashlib from .eventwebhook_header import EventWebhookHeader class EventWebhook: @@ -20,15 +21,15 @@ def __init__(self, public_key=None): def convert_public_key_to_ecdsa(self, public_key): """ - Convert the public key string to a VerifyingKey object. + Convert the public key string to an EllipticCurvePublicKey object. :param public_key: verification key under Mail Settings :type public_key string - :return: VerifyingKey object using the ECDSA algorithm - :rtype VerifyingKey + :return: An EllipticCurvePublicKey object using the ECDSA algorithm + :rtype cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey """ pem_key = "-----BEGIN PUBLIC KEY-----\n" + public_key + "\n-----END PUBLIC KEY-----" - return VerifyingKey.from_pem(pem_key) + return load_pem_public_key(pem_key.encode("utf-8")) def verify_signature(self, payload, signature, timestamp, public_key=None): """ @@ -41,7 +42,7 @@ def verify_signature(self, payload, signature, timestamp, public_key=None): :param timestamp: value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header :type timestamp: string :param public_key: elliptic curve public key - :type public_key: VerifyingKey + :type public_key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey :return: true or false if signature is valid """ timestamped_payload = (timestamp + payload).encode('utf-8') @@ -49,7 +50,7 @@ def verify_signature(self, payload, signature, timestamp, public_key=None): key = public_key or self.public_key try: - key.verify(decoded_signature, timestamped_payload, hashfunc=hashlib.sha256, sigdecode=sigdecode_der) + key.verify(decoded_signature, timestamped_payload, ec.ECDSA(hashes.SHA256())) return True - except BadSignatureError: + except InvalidSignature: return False diff --git a/setup.py b/setup.py index 745edea81..904cd654a 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def getRequires(): deps = [ 'python_http_client>=3.2.1', - 'ecdsa>=0.19.1,<1', + 'cryptography>=45.0.6', "werkzeug>=0.11.15,<1.0.0 ; python_version < '3.0'", "werkzeug>=0.15.0,<2.0.0 ; python_version >= '3.0' and python_version < '3.7'", "werkzeug>=0.15.0,<2.3.0 ; python_version >= '3.0' and python_version < '3.8'", # version 2.3.0 dropped support for Python 3.7 From 5e26ead73a8d908550b4fab3166ab41697030c9c Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Fri, 19 Sep 2025 11:47:28 +0530 Subject: [PATCH 101/102] [Librarian] Version Bump --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87dde6650..67d327649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ # Change Log All notable changes to this project will be documented in this file. +[2025-09-19] Version 6.12.5 +--------------------------- +**Library - Fix** +- [PR #1114](https://github.com/sendgrid/sendgrid-python/pull/1114): #1108 - Replace ecdsa with cryptography. Thanks to [@dacevedo12](https://github.com/dacevedo12)! + +**Library - Chore** +- [PR #1117](https://github.com/sendgrid/sendgrid-python/pull/1117): use make-test instead of make test-docker. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + + [2025-06-12] Version 6.12.4 --------------------------- **Library - Chore** From 76788e70a76b11ce2990821f190e52f887ab9ed6 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Fri, 19 Sep 2025 11:48:40 +0530 Subject: [PATCH 102/102] Release 6.12.5 --- sendgrid/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendgrid/version.py b/sendgrid/version.py index 127e2ed69..c1d623f90 100644 --- a/sendgrid/version.py +++ b/sendgrid/version.py @@ -1 +1 @@ -__version__ = '6.12.4' +__version__ = '6.12.5'