@@ -22,7 +22,8 @@ class Client(object):
2222 """ A client for accessing the Twilio API. """
2323
2424 def __init__ (self , username = None , password = None , account_sid = None , region = None ,
25- http_client = None , environment = None , edge = None ):
25+ http_client = None , environment = None , edge = None ,
26+ user_agent_extensions = None ):
2627 """
2728 Initializes the Twilio Client
2829
@@ -33,6 +34,7 @@ def __init__(self, username=None, password=None, account_sid=None, region=None,
3334 :param HttpClient http_client: HttpClient, defaults to TwilioHttpClient
3435 :param dict environment: Environment to look for auth details, defaults to os.environ
3536 :param str edge: Twilio Edge to make requests to, defaults to None
37+ :param list[str] user_agent_extensions: Additions to the user agent string
3638
3739 :returns: Twilio Client
3840 :rtype: twilio.rest.Client
@@ -49,6 +51,8 @@ def __init__(self, username=None, password=None, account_sid=None, region=None,
4951 """ :type : str """
5052 self .region = region or environment .get ('TWILIO_REGION' )
5153 """ :type : str """
54+ self .user_agent_extensions = user_agent_extensions or []
55+ """ :type : list[str] """
5256
5357 if not self .username or not self .password :
5458 raise TwilioException ("Credentials are required to create a TwilioClient" )
@@ -113,10 +117,18 @@ def request(self, method, uri, params=None, data=None, headers=None, auth=None,
113117 auth = auth or self .auth
114118 headers = headers or {}
115119
116- headers ['User-Agent' ] = 'twilio-python/{} (Python {})' .format (
117- __version__ ,
118- platform .python_version (),
120+ pkg_version = __version__
121+ os_name = platform .system ()
122+ os_arch = platform .machine ()
123+ python_version = platform .python_version ()
124+ headers ['User-Agent' ] = 'twilio-python/{} ({} {}) Python/{}' .format (
125+ pkg_version ,
126+ os_name ,
127+ os_arch ,
128+ python_version ,
119129 )
130+ for extension in self .user_agent_extensions :
131+ headers ['User-Agent' ] += ' {}' .format (extension )
120132 headers ['X-Twilio-Client' ] = 'python-{}' .format (__version__ )
121133 headers ['Accept-Charset' ] = 'utf-8'
122134
0 commit comments