telesign 2.3.0__py2.py3-none-any.whl → 3.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
telesign/rest.py CHANGED
@@ -6,6 +6,7 @@ from base64 import b64encode, b64decode
6
6
  from email.utils import formatdate
7
7
  from hashlib import sha256
8
8
  from platform import python_version
9
+ import time
9
10
 
10
11
  import requests
11
12
  import json
@@ -52,7 +53,8 @@ class RestClient(requests.models.RequestEncodingMixin):
52
53
  sdk_version_dependency=None,
53
54
  proxies=None,
54
55
  timeout=10,
55
- auth_method=None):
56
+ auth_method=None,
57
+ pool_recycle=480):
56
58
  """
57
59
  Telesign RestClient useful for making generic RESTful requests against our API.
58
60
 
@@ -62,13 +64,22 @@ class RestClient(requests.models.RequestEncodingMixin):
62
64
  :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy.
63
65
  :param timeout: (optional) How long to wait for the server to send data before giving up, as a float,
64
66
  or as a (connect timeout, read timeout) tuple
67
+ :param pool_recycle: (optional) Time in seconds to recycle the HTTP session to avoid stale connections (default 480).
68
+ If a session is older than this value, it will be closed and a new session will be created automatically before each request.
69
+ This helps prevent errors due to HTTP keep-alive connections being closed by the server after inactivity.
70
+
71
+ HTTP Keep-Alive behavior:
72
+ TeleSign endpoints close idle HTTP keep-alive connections after 499 seconds. If you attempt to reuse a connection older than this, you may get a 'connection reset by peer' error.
73
+ By default, pool_recycle=480 ensures sessions are refreshed before this limit.
65
74
  """
66
75
  self.customer_id = customer_id
67
76
  self.api_key = api_key
68
77
 
69
78
  self.api_host = rest_endpoint
70
79
 
71
- self.session = requests.Session()
80
+ self.pool_recycle = pool_recycle
81
+ self._session_created_at = None
82
+ self.session = self._create_session()
72
83
 
73
84
  self.session.proxies = proxies if proxies else {}
74
85
 
@@ -234,6 +245,17 @@ class RestClient(requests.models.RequestEncodingMixin):
234
245
  """
235
246
  return self._execute(self.session.patch, 'PATCH', resource, body, json_fields, **query_params)
236
247
 
248
+ def _create_session(self):
249
+ session = requests.Session()
250
+ self._session_created_at = time.time()
251
+ return session
252
+
253
+ def _ensure_session(self):
254
+ if self._session_created_at is None or (time.time() - self._session_created_at > self.pool_recycle):
255
+ if self.session:
256
+ self.session.close()
257
+ self.session = self._create_session()
258
+
237
259
  def _execute(self, method_function, method_name, resource, body=None, json_fields=None, **query_params):
238
260
  """
239
261
  Generic Telesign REST API request handler.
@@ -245,6 +267,7 @@ class RestClient(requests.models.RequestEncodingMixin):
245
267
  :param query_params: query_params to perform the HTTP request with, as a dictionary.
246
268
  :return: The RestClient Response object.
247
269
  """
270
+ self._ensure_session()
248
271
  resource_uri = "{api_host}{resource}".format(api_host=self.api_host, resource=resource)
249
272
 
250
273
  url_encoded_fields = self._encode_params(query_params)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: telesign
3
- Version: 2.3.0
3
+ Version: 3.0.0
4
4
  Summary: TeleSign SDK
5
5
  Home-page: https://github.com/telesign/python_telesign
6
6
  Author: TeleSign Corp.
@@ -0,0 +1,12 @@
1
+ telesign/__init__.py,sha256=D8kANX0FKxBD7-a7xQ21xPz3ojM2WAOK8lThGLtDZuE,367
2
+ telesign/messaging.py,sha256=v7l-eKUPqz7Nrwka0YNPMkC2TaoFUvQm3yp_djuTPu0,1367
3
+ telesign/phoneid.py,sha256=mk03NxL3wlaXpd8b-BB6q_SKfCxbtuTO19ayAHxmzz0,954
4
+ telesign/rest.py,sha256=AHNDyVZLa1vm2RWD4TSxr6uM4K50eH29C2Kjr3eCq8c,13911
5
+ telesign/score.py,sha256=Kceu6IrirN9SsuT1geEWs0QHAn6H9ZNFyIDVHcBJdwg,908
6
+ telesign/util.py,sha256=stDxpL5ZQeGskE_OSGP04UFHs3ZP2ACaRpW1WyQGMHg,1624
7
+ telesign/voice.py,sha256=DJaWyQpun-T7LfNjpxpsUjupiv2ShW1jqoFQA-CE2-Y,1341
8
+ telesign-3.0.0.dist-info/LICENSE.txt,sha256=a--xZ4PCKUL5rpct8RrUC6ODU_8ZKIU51kJPfsA4HUs,1058
9
+ telesign-3.0.0.dist-info/METADATA,sha256=FbEOaOQ1w0LnFmiKDKo3SnGJKZ56Lf19ltUg83dYZ0g,4532
10
+ telesign-3.0.0.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
11
+ telesign-3.0.0.dist-info/top_level.txt,sha256=6LG7Jcr1jnpVhOWaIShoTdwYJn0QCfPhfudyVJNz1qg,9
12
+ telesign-3.0.0.dist-info/RECORD,,
telesign/appverify.py DELETED
@@ -1,28 +0,0 @@
1
- from __future__ import unicode_literals
2
-
3
- from telesign.rest import RestClient
4
-
5
- APPVERIFY_STATUS_RESOURCE = "/v1/mobile/verification/status/{external_id}"
6
-
7
-
8
- class AppVerifyClient(RestClient):
9
- """
10
- App Verify is a secure, lightweight SDK that integrates a frictionless user verification process into existing
11
- native mobile applications.
12
- """
13
-
14
- def __init__(self, customer_id, api_key, **kwargs):
15
- super(AppVerifyClient, self).__init__(customer_id, api_key, **kwargs)
16
-
17
- def status(self, external_id, **params):
18
- """
19
- Retrieves the verification result for an App Verify transaction by external_id. To ensure a secure verification
20
- flow you must check the status using TeleSign's servers on your backend. Do not rely on the SDK alone to
21
- indicate a successful verification.
22
-
23
- See https://developer.telesign.com/docs/app-verify-android-sdk-self#section-get-status-service or
24
- https://developer.telesign.com/docs/app-verify-ios-sdk-self#section-get-status-service for detailed
25
- API documentation.
26
- """
27
- return self.get(APPVERIFY_STATUS_RESOURCE.format(external_id=external_id),
28
- **params)
telesign/intelligence.py DELETED
@@ -1,39 +0,0 @@
1
- """Client to make requests to intelligence API."""
2
- from __future__ import unicode_literals
3
-
4
- from telesign.rest import RestClient
5
- from telesign.util import AuthMethod
6
-
7
- INTELLIGENCE_BASE_URL = "https://detect.telesign.com"
8
- INTELLIGENCE_ENDPOINT_PATH = "/intelligence"
9
-
10
-
11
- class IntelligenceClient(RestClient):
12
- """
13
- It is critical today to evaluate fraud risk throughout the entire customer journey.
14
-
15
- Telesign Intelligence makes it easy to understand the risk and the reason behind it with tailored scoring models
16
- and comprehensive reason codes.
17
- """
18
-
19
- def __init__(self, customer_id, api_key, **kwargs):
20
- super(IntelligenceClient, self).__init__(
21
- customer_id=customer_id,
22
- api_key=api_key,
23
- rest_endpoint=INTELLIGENCE_BASE_URL,
24
- auth_method=AuthMethod.BASIC.value,
25
- **kwargs
26
- )
27
-
28
- def intelligence(self, params):
29
- """
30
- Telesign Intelligence is like a credit check for digital profiles.
31
-
32
- You submit a phone number, IP, and email to the service, the individual
33
- identifiers are each evaluated, and then a score is returned telling you how risky
34
- that user is. You decide whether to proceed based on the score.
35
-
36
- See https://developer.telesign.com/enterprise/docs/intelligence-overview
37
- for detailed API documentation.
38
- """
39
- return self.post(INTELLIGENCE_ENDPOINT_PATH, body=params, query_params=None)
@@ -1,14 +0,0 @@
1
- telesign/__init__.py,sha256=D8kANX0FKxBD7-a7xQ21xPz3ojM2WAOK8lThGLtDZuE,367
2
- telesign/appverify.py,sha256=wBeaeUxGmYcZkrbxkkXlG3-0oZr5sVvegzVpdvaoO2A,1195
3
- telesign/intelligence.py,sha256=t-xwlgxkXw1OMupF5K4_UKWeTArOr9XPvddmqgZftPI,1452
4
- telesign/messaging.py,sha256=v7l-eKUPqz7Nrwka0YNPMkC2TaoFUvQm3yp_djuTPu0,1367
5
- telesign/phoneid.py,sha256=mk03NxL3wlaXpd8b-BB6q_SKfCxbtuTO19ayAHxmzz0,954
6
- telesign/rest.py,sha256=26EESKSPzSPIAf3VpVmCEPE8HSpAZRfGw5koIHsJeh8,12653
7
- telesign/score.py,sha256=Kceu6IrirN9SsuT1geEWs0QHAn6H9ZNFyIDVHcBJdwg,908
8
- telesign/util.py,sha256=stDxpL5ZQeGskE_OSGP04UFHs3ZP2ACaRpW1WyQGMHg,1624
9
- telesign/voice.py,sha256=DJaWyQpun-T7LfNjpxpsUjupiv2ShW1jqoFQA-CE2-Y,1341
10
- telesign-2.3.0.dist-info/LICENSE.txt,sha256=a--xZ4PCKUL5rpct8RrUC6ODU_8ZKIU51kJPfsA4HUs,1058
11
- telesign-2.3.0.dist-info/METADATA,sha256=7pxOUYH6cvpiHfYp7v0GFYN9Wgz3ZWqahdN3qHfm__g,4532
12
- telesign-2.3.0.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
13
- telesign-2.3.0.dist-info/top_level.txt,sha256=6LG7Jcr1jnpVhOWaIShoTdwYJn0QCfPhfudyVJNz1qg,9
14
- telesign-2.3.0.dist-info/RECORD,,