label-studio-sdk 0.0.28__tar.gz → 0.0.29__tar.gz
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.
Potentially problematic release.
This version of label-studio-sdk might be problematic. Click here for more details.
- {label-studio-sdk-0.0.28/label_studio_sdk.egg-info → label-studio-sdk-0.0.29}/PKG-INFO +1 -1
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/README.md +5 -1
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/__init__.py +1 -1
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/client.py +37 -11
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29/label_studio_sdk.egg-info}/PKG-INFO +1 -1
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/LICENSE +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/MANIFEST.in +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/docs/__init__.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/data_manager.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/project.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/users.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/utils.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk/workspaces.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk.egg-info/SOURCES.txt +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk.egg-info/dependency_links.txt +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk.egg-info/requires.txt +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk.egg-info/top_level.txt +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/requirements.txt +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/setup.cfg +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/setup.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/tests/__init__.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/tests/import_test.py +0 -0
- {label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/tests/test_client.py +0 -0
|
@@ -17,7 +17,7 @@ If you want to take action not supported natively by the SDK, you can [call the
|
|
|
17
17
|
This is the first release of the Label Studio SDK. It supports Label Studio Enterprise, Label Studio Teams, and Label Studio Community.
|
|
18
18
|
|
|
19
19
|
- **Find a bug?** [Create a GitHub issue](https://github.com/heartexlabs/label-studio-sdk/issues)!
|
|
20
|
-
- **Have a question?** [Join the Slack Community](https://slack.
|
|
20
|
+
- **Have a question?** [Join the Slack Community](https://slack.labelstud.io/?source=github-sdk)!
|
|
21
21
|
- **Want to contribute?** [See the contributing guide](https://github.com/heartexlabs/label-studio-sdk/CONTRIBUTING.md)
|
|
22
22
|
|
|
23
23
|
## Quickstart
|
|
@@ -43,6 +43,10 @@ The Label Studio SDK includes the following:
|
|
|
43
43
|
|
|
44
44
|
For all the details, see the [reference documentation](https://labelstud.io/sdk) or [review the code directly](https://github.com/heartexlabs/label-studio-sdk/tree/master/label_studio_sdk).
|
|
45
45
|
|
|
46
|
+
## Error logging
|
|
47
|
+
|
|
48
|
+
To see error logs, you can use `stderr` (we use `logger.error()` for error output). If you use console to run SDK commands, you will see all errors there.
|
|
49
|
+
|
|
46
50
|
## Contribute to the SDK
|
|
47
51
|
|
|
48
52
|
If you want to extend the SDK:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
""" .. include::../docs/client.md
|
|
2
2
|
"""
|
|
3
|
+
import json
|
|
3
4
|
import warnings
|
|
4
5
|
import logging
|
|
5
6
|
import requests
|
|
@@ -7,11 +8,12 @@ import requests
|
|
|
7
8
|
from typing import Optional
|
|
8
9
|
from pydantic import BaseModel, constr, root_validator
|
|
9
10
|
from requests.adapters import HTTPAdapter
|
|
11
|
+
from types import SimpleNamespace
|
|
10
12
|
|
|
11
13
|
logger = logging.getLogger(__name__)
|
|
12
14
|
|
|
13
15
|
MAX_RETRIES = 3
|
|
14
|
-
TIMEOUT = (
|
|
16
|
+
TIMEOUT = (10.0, 180.0)
|
|
15
17
|
HEADERS = {}
|
|
16
18
|
|
|
17
19
|
|
|
@@ -258,7 +260,7 @@ class Client(object):
|
|
|
258
260
|
users.append(User(**user_data))
|
|
259
261
|
return users
|
|
260
262
|
|
|
261
|
-
def create_user(self, user):
|
|
263
|
+
def create_user(self, user, exist_ok=True):
|
|
262
264
|
"""Create a new user
|
|
263
265
|
|
|
264
266
|
Parameters
|
|
@@ -266,6 +268,8 @@ class Client(object):
|
|
|
266
268
|
user: User or dict
|
|
267
269
|
User instance, you can initialize it this way:
|
|
268
270
|
User(username='x', email='x@x.xx', first_name='X', last_name='Z')
|
|
271
|
+
exist_ok: bool
|
|
272
|
+
True by default, it won't print error if user exists and exist_ok=True
|
|
269
273
|
|
|
270
274
|
Returns
|
|
271
275
|
-------
|
|
@@ -277,7 +281,7 @@ class Client(object):
|
|
|
277
281
|
|
|
278
282
|
payload = (
|
|
279
283
|
{
|
|
280
|
-
'username': user.username,
|
|
284
|
+
'username': user.username if user.username else user.email,
|
|
281
285
|
'email': user.email,
|
|
282
286
|
'first_name': user.first_name,
|
|
283
287
|
'last_name': user.last_name,
|
|
@@ -287,13 +291,16 @@ class Client(object):
|
|
|
287
291
|
else user
|
|
288
292
|
)
|
|
289
293
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
+
response = self.make_request('POST', '/api/users', json=payload, raise_exceptions=False)
|
|
295
|
+
user_data = response.json()
|
|
296
|
+
user_data['client'] = self
|
|
297
|
+
|
|
298
|
+
if response.status_code < 400:
|
|
294
299
|
return User(**user_data)
|
|
295
|
-
|
|
296
|
-
|
|
300
|
+
else:
|
|
301
|
+
if 'already exists' in response.text and exist_ok is True:
|
|
302
|
+
return None
|
|
303
|
+
logger.error('Create user error: ' + str(response.json()))
|
|
297
304
|
return None
|
|
298
305
|
|
|
299
306
|
def get_workspaces(self):
|
|
@@ -366,6 +373,11 @@ class Client(object):
|
|
|
366
373
|
"""
|
|
367
374
|
if 'timeout' not in kwargs:
|
|
368
375
|
kwargs['timeout'] = TIMEOUT
|
|
376
|
+
|
|
377
|
+
raise_exceptions = self.make_request_raise
|
|
378
|
+
if 'raise_exceptions' in kwargs: # kwargs have higher priority
|
|
379
|
+
raise_exceptions = kwargs.pop('raise_exceptions')
|
|
380
|
+
|
|
369
381
|
logger.debug(f'{method}: {url} with args={args}, kwargs={kwargs}')
|
|
370
382
|
response = self.session.request(
|
|
371
383
|
method,
|
|
@@ -375,8 +387,22 @@ class Client(object):
|
|
|
375
387
|
*args,
|
|
376
388
|
**kwargs,
|
|
377
389
|
)
|
|
378
|
-
|
|
379
|
-
|
|
390
|
+
|
|
391
|
+
if raise_exceptions:
|
|
392
|
+
if response.status_code >= 400:
|
|
393
|
+
try:
|
|
394
|
+
content = json.dumps(json.loads(response.content), indent=2)
|
|
395
|
+
except:
|
|
396
|
+
content = response.text
|
|
397
|
+
|
|
398
|
+
logger.error(
|
|
399
|
+
f'\n--------------------------------------------\n'
|
|
400
|
+
f'Request URL: {response.url}\n'
|
|
401
|
+
f'Response status code: {response.status_code}\n'
|
|
402
|
+
f'Response content:\n{content}\n\n'
|
|
403
|
+
f'SDK error traceback:')
|
|
404
|
+
response.raise_for_status()
|
|
405
|
+
|
|
380
406
|
return response
|
|
381
407
|
|
|
382
408
|
def sync_storage(self, storage_type, storage_id):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{label-studio-sdk-0.0.28 → label-studio-sdk-0.0.29}/label_studio_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|