Skip to content

Commit 9e04b5e

Browse files
adding proxy support to SDK (#72)
1 parent a3efe50 commit 9e04b5e

File tree

4 files changed

+76
-15
lines changed

4 files changed

+76
-15
lines changed

README.rst

+29-11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ _____
4242
4343
client = scaleapi.ScaleClient("YOUR_API_KEY_HERE")
4444
45+
If you need to use a proxy to connect Scale API, you can feed ``proxies``, ``cert`` and ``verify`` attributes of the python ``requests`` package during the client initialization.
46+
Proxy support is available with SDK version 2.14.0 and beyond.
47+
48+
`Documentation of Proxies usage in requests package`__
49+
50+
__ https://requests.readthedocs.io/en/latest/user/advanced/#proxies
51+
52+
.. code-block:: python
53+
54+
proxies = { 'https': 'http://10.10.1.10:1080' }
55+
56+
client = scaleapi.ScaleClient(
57+
api_key="YOUR_API_KEY_HERE",
58+
proxies=proxies,
59+
cert='/path/client.cert',
60+
verify=True
61+
)
62+
4563
Tasks
4664
_____
4765

@@ -358,7 +376,7 @@ __ https://docs.scale.com/reference/deleting-tags
358376
# delete a list of tags on a task by specifying task id
359377
tags_to_delete = ["tag1", "tag2"]
360378
task = client.delete_task_tags('30553edd0b6a93f8f05f0fee', tags_to_delete)
361-
379+
362380
# delete a list of tags on a task object
363381
task = client.get_task('30553edd0b6a93f8f05f0fee')
364382
tags_to_delete = ["tag1", "tag2"]
@@ -600,7 +618,7 @@ The attribute can be passed to the task payloads, in the ``attachment`` paramete
600618
...
601619
...
602620
)
603-
621+
604622
Manage Teammates
605623
________________
606624

@@ -628,9 +646,9 @@ Returns all teammates in a List of Teammate objects.
628646
.. code-block:: python
629647
630648
from scaleapi import TeammateRole
631-
649+
632650
teammates = client.invite_teammates(['[email protected]', '[email protected]'], TeammateRole.Member)
633-
651+
634652
Update Teammate Role
635653
^^^^^^^^^^^^^^^^^^^^^
636654

@@ -641,7 +659,7 @@ Returns all teammates in a List of Teammate objects.
641659
.. code-block python
642660
643661
from scaleapi import TeammateRole
644-
662+
645663
teammates = client.update_teammates_role(['[email protected]', '[email protected]'], TeammateRole.Manager)
646664
647665
Example Scripts
@@ -738,7 +756,7 @@ Manage project assignments for your labelers.
738756
List All Assignments
739757
^^^^^^^^^^^^^^^^^^^^
740758

741-
Lists all your Scale team members and the projects they are assigned to.
759+
Lists all your Scale team members and the projects they are assigned to.
742760
Returns a dictionary of all teammate assignments with keys as 'emails' of each teammate, and values as a list of project names the teammate are assigned to.
743761

744762
.. code-block:: python
@@ -772,7 +790,7 @@ Returns a dictionary of all teammate assignments with keys as 'emails' of each t
772790
.. code-block:: python
773791
774792
assignments = client.remove_studio_assignments(['[email protected]', '[email protected]'], ['project 1', 'project 2'])
775-
793+
776794
Studio Project Groups (For Scale Studio Only)
777795
_____________________________________________
778796

@@ -784,7 +802,7 @@ List Studio Project Groups
784802
Returns all labeler groups for the specified project.
785803

786804
.. code-block:: python
787-
805+
788806
list_project_group = client.list_project_groups('project_name')
789807
790808
Add Studio Project Group
@@ -803,7 +821,7 @@ Returns the created StudioProjectGroup object.
803821
Update Studio Project Group
804822
^^^^^^^^^^^^^^^^^^^^^^^^^^^
805823

806-
Assign or remove teammates from a project group.
824+
Assign or remove teammates from a project group.
807825

808826
Returns the updated StudioProjectGroup object.
809827

@@ -812,7 +830,7 @@ Returns the updated StudioProjectGroup object.
812830
updated_project_group = client.update_project_group(
813831
'project_name', 'project_group_name', ['emails_to_add'], ['emails_to_remove']
814832
)
815-
833+
816834
Studio Batches (For Scale Studio Only)
817835
_______________________________________
818836

@@ -835,7 +853,7 @@ Sets labeler group assignment for the specified batch.
835853
Returns a StudioBatch object for the specified batch.
836854

837855
.. code-block:: python
838-
856+
839857
assigned_studio_batch = client.assign_studio_batches('batch_name', ['project_group_name'])
840858
841859
Set Studio Batches Priority

scaleapi/__init__.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ class Batchlist(Paginator[Batch]):
4848
class ScaleClient:
4949
"""Main class serves as an interface for Scale API"""
5050

51-
def __init__(self, api_key, source=None, api_instance_url=None):
51+
def __init__(
52+
self,
53+
api_key,
54+
source=None,
55+
api_instance_url=None,
56+
verify=None,
57+
proxies=None,
58+
cert=None,
59+
):
5260
self.api = Api(
5361
api_key,
5462
user_agent_extension=source,
5563
api_instance_url=api_instance_url,
64+
verify=verify,
65+
proxies=proxies,
66+
cert=cert,
5667
)
5768

5869
def get_task(self, task_id: str) -> Task:

scaleapi/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "2.13.1"
1+
__version__ = "2.14.0"
22
__package_name__ = "scaleapi"

scaleapi/api.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
class Api:
2020
"""Internal Api reference for handling http operations"""
2121

22-
def __init__(self, api_key, user_agent_extension=None, api_instance_url=None):
22+
def __init__(
23+
self,
24+
api_key,
25+
user_agent_extension=None,
26+
api_instance_url=None,
27+
verify=None,
28+
proxies=None,
29+
cert=None,
30+
):
2331
if api_key == "" or api_key is None:
2432
raise ScaleException("Please provide a valid API Key.")
2533

@@ -35,6 +43,10 @@ def __init__(self, api_key, user_agent_extension=None, api_instance_url=None):
3543
}
3644
self.base_api_url = api_instance_url or SCALE_API_BASE_URL_V1
3745

46+
self.verify = verify
47+
self.proxies = proxies
48+
self.cert = cert
49+
3850
@staticmethod
3951
def _http_request(
4052
method,
@@ -45,6 +57,9 @@ def _http_request(
4557
body=None,
4658
files=None,
4759
data=None,
60+
verify=None,
61+
proxies=None,
62+
cert=None,
4863
) -> Response:
4964
https = requests.Session()
5065
retry_strategy = Retry(
@@ -58,6 +73,11 @@ def _http_request(
5873
adapter = HTTPAdapter(max_retries=retry_strategy)
5974
https.mount("https://", adapter)
6075

76+
https.cert = cert if cert else None
77+
https.verify = verify if verify else True
78+
if proxies:
79+
https.proxies.update(proxies)
80+
6181
try:
6282
params = params or {}
6383
body = body or None
@@ -102,7 +122,19 @@ def _api_request(
102122

103123
url = f"{self.base_api_url}/{endpoint}"
104124

105-
res = self._http_request(method, url, headers, auth, params, body, files, data)
125+
res = self._http_request(
126+
method,
127+
url,
128+
headers,
129+
auth,
130+
params,
131+
body,
132+
files,
133+
data,
134+
verify=self.verify,
135+
proxies=self.proxies,
136+
cert=self.cert,
137+
)
106138

107139
json = None
108140
if res.status_code == 200:

0 commit comments

Comments
 (0)