1
1
import requests
2
+ import platform
2
3
3
4
from .tasks import Task
4
5
from .batches import Batch
5
6
from .projects import Project
7
+ from ._version import __version__
6
8
7
9
TASK_TYPES = [
8
10
'annotation' ,
@@ -63,6 +65,10 @@ class Batchlist(Paginator):
63
65
class ScaleClient (object ):
64
66
def __init__ (self , api_key ):
65
67
self .api_key = api_key
68
+ self ._headers = {
69
+ "Content-Type" : "application/json" ,
70
+ "User-Agent" : _generate_useragent ()
71
+ }
66
72
67
73
def _getrequest (self , endpoint , params = None ):
68
74
"""Makes a get request to an endpoint.
@@ -73,7 +79,7 @@ def _getrequest(self, endpoint, params=None):
73
79
"""
74
80
params = params or {}
75
81
r = requests .get (SCALE_ENDPOINT + endpoint ,
76
- headers = { "Content-Type" : "application/json" } ,
82
+ headers = self . _headers ,
77
83
auth = (self .api_key , '' ), params = params )
78
84
79
85
if r .status_code == 200 :
@@ -97,7 +103,7 @@ def _postrequest(self, endpoint, payload=None):
97
103
"""
98
104
payload = payload or {}
99
105
r = requests .post (SCALE_ENDPOINT + endpoint , json = payload ,
100
- headers = { "Content-Type" : "application/json" } ,
106
+ headers = self . _headers ,
101
107
auth = (self .api_key , '' ))
102
108
103
109
if r .status_code == 200 :
@@ -212,6 +218,15 @@ def update_project(self, project_name, **kwargs):
212
218
projectdata = self ._postrequest ('projects/%s/setParams' % project_name , payload = kwargs )
213
219
return projectdata
214
220
221
+ def _generate_useragent ():
222
+ try :
223
+ python_version = platform .python_version ()
224
+ os_platform = platform .platform ()
225
+
226
+ user_agent = '%s/%s Python/%s OS/%s' % (__name__ , __version__ , python_version , os_platform )
227
+ return user_agent
228
+ except :
229
+ return "scaleapi-python-client"
215
230
216
231
def _AddTaskTypeCreator (task_type ):
217
232
def create_task_wrapper (self , ** kwargs ):
0 commit comments