Skip to content

Commit

Permalink
feat: geolocation setter in sendgrid-python for GDPR compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
manisha1997 committed Nov 22, 2023
1 parent f86747b commit 0a95877
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
23 changes: 3 additions & 20 deletions examples/dataresidency/set_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,23 @@
# setting region to be "global"

sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
sg.set_data_residency("global")
from_email = Email("[email protected]")
to_email = To("[email protected]")
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)
sg.set_sendgrid_data_residency("global")
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 host
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
sg.set_host("https://api.eu.sendgrid.com")
from_email = Email("[email protected]")
to_email = To("[email protected]")
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)

# Example 3
# setting region to "eu"
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
sg.set_data_residency("eu")
sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY_EU'))
sg.set_sendgrid_data_residency("eu")
from_email = Email("[email protected]")
to_email = To("[email protected]")
subject = "Sending with SendGrid is Fun"
Expand Down
2 changes: 1 addition & 1 deletion sendgrid/base_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def send(self, message):

return self.client.mail.send.post(request_body=message)

def set_data_residency(self, region):
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.
Expand Down

0 comments on commit 0a95877

Please sign in to comment.