11import python_http_client
22
3+ region_host_dict = {'eu' :'https://api.eu.sendgrid.com' ,'global' :'https://api.sendgrid.com' }
34
45class BaseInterface (object ):
56 def __init__ (self , auth , host , impersonate_subuser ):
@@ -22,10 +23,10 @@ def __init__(self, auth, host, impersonate_subuser):
2223 """
2324 from . import __version__
2425 self .auth = auth
25- self .host = host
2626 self .impersonate_subuser = impersonate_subuser
2727 self .version = __version__
2828 self .useragent = 'sendgrid/{};python' .format (self .version )
29+ self .host = host
2930
3031 self .client = python_http_client .Client (
3132 host = self .host ,
@@ -60,3 +61,23 @@ def send(self, message):
6061 message = message .get ()
6162
6263 return self .client .mail .send .post (request_body = message )
64+
65+ def set_sendgrid_data_residency (self , region ):
66+ """
67+ Client libraries contain setters for specifying region/edge.
68+ This supports global and eu regions only. This set will likely expand in the future.
69+ Global is the default residency (or region)
70+ Global region means the message will be sent through https://api.sendgrid.com
71+ EU region means the message will be sent through https://api.eu.sendgrid.com
72+ :param region: string
73+ :return:
74+ """
75+ if region in region_host_dict .keys ():
76+ self .host = region_host_dict [region ]
77+ if self ._default_headers is not None :
78+ self .client = python_http_client .Client (
79+ host = self .host ,
80+ request_headers = self ._default_headers ,
81+ version = 3 )
82+ else :
83+ raise ValueError ("region can only be \" eu\" or \" global\" " )
0 commit comments