Skip to content

Commit 6380eda

Browse files
authored
Merge branch 'develop' into pno/PLT-2480_get_invites
2 parents 7af08b9 + 688aea7 commit 6380eda

File tree

10 files changed

+741
-19
lines changed

10 files changed

+741
-19
lines changed

.github/workflows/python-package-develop.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,15 @@ jobs:
6161
- python-version: "3.9"
6262
api-key: STAGING_LABELBOX_API_KEY_3
6363
da-test-key: DA_GCP_LABELBOX_API_KEY
64-
sdk-version: ${{ fromJson(needs.get_sdk_versions.outputs.sdk_versions)[3] }}
6564
- python-version: "3.10"
6665
api-key: STAGING_LABELBOX_API_KEY_4
6766
da-test-key: DA_GCP_LABELBOX_API_KEY
68-
sdk-version: ${{ fromJson(needs.get_sdk_versions.outputs.sdk_versions)[2] }}
6967
- python-version: "3.11"
7068
api-key: STAGING_LABELBOX_API_KEY
7169
da-test-key: DA_GCP_LABELBOX_API_KEY
72-
sdk-version: ${{ fromJson(needs.get_sdk_versions.outputs.sdk_versions)[1] }}
7370
- python-version: "3.12"
7471
api-key: STAGING_LABELBOX_API_KEY_5
75-
da-test-key: DA_GCP_LABELBOX_API_KEY
76-
sdk-version: ${{ fromJson(needs.get_sdk_versions.outputs.sdk_versions)[0] }}
72+
da-test-key: DA_GCP_LABELBOX_API_KEY
7773
- python-version: "3.13"
7874
api-key: STAGING_LABELBOX_API_KEY_2
7975
da-test-key: DA_GCP_LABELBOX_API_KEY

libs/labelbox/src/labelbox/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@
9999
)
100100
from lbox.exceptions import *
101101
from labelbox.schema.taskstatus import TaskStatus
102+
from labelbox.schema.api_key import ApiKey
103+
from labelbox.schema.timeunit import TimeUnit

libs/labelbox/src/labelbox/client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
from labelbox.schema.task import DataUpsertTask, Task
8181
from labelbox.schema.user import User
8282
from labelbox.schema.taskstatus import TaskStatus
83+
from labelbox.schema.api_key import ApiKey
84+
from labelbox.schema.timeunit import TimeUnit
8385

8486
logger = logging.getLogger(__name__)
8587

@@ -2456,3 +2458,61 @@ def cancel_task(self, task_id: str) -> bool:
24562458
"""
24572459
res = self.execute(mutation_str, {"id": task_id})
24582460
return res["cancelBulkOperationJob"]["success"]
2461+
2462+
def create_api_key(
2463+
self,
2464+
name: str,
2465+
user: Union[User, str],
2466+
role: Union[Role, str],
2467+
validity: int = 0,
2468+
time_unit: TimeUnit = TimeUnit.SECOND,
2469+
refresh_cache: bool = False,
2470+
) -> Dict[str, str]:
2471+
"""Creates a new API key.
2472+
2473+
Args:
2474+
name (str): The name of the API key.
2475+
user (Union[User, str]): The user object or user ID to associate with the API key.
2476+
role (Union[Role, str]): The role object or role ID to assign to the API key.
2477+
validity (int, optional): The validity period of the API key. Defaults to 0 (no expiration).
2478+
time_unit (TimeUnit, optional): The time unit for the validity period. Defaults to TimeUnit.SECOND.
2479+
refresh_cache (bool, optional): Whether to refresh cached permissions and roles. Defaults to False.
2480+
2481+
Returns:
2482+
Dict[str, str]: A dictionary containing the created API key information.
2483+
"""
2484+
warnings.warn(
2485+
"The creation of API keys is currently in alpha and its behavior may change in future releases.",
2486+
)
2487+
if refresh_cache:
2488+
# Clear cached attributes if they exist
2489+
if hasattr(self, "_cached_current_user_permissions"):
2490+
delattr(self, "_cached_current_user_permissions")
2491+
if hasattr(self, "_cached_available_api_key_roles"):
2492+
delattr(self, "_cached_available_api_key_roles")
2493+
2494+
return ApiKey.create_api_key(
2495+
self, name, user, role, validity, time_unit
2496+
)
2497+
2498+
def get_api_keys(self, include_expired: bool = False) -> List[ApiKey]:
2499+
"""Retrieves all API keys accessible to the current user.
2500+
2501+
Args:
2502+
include_revoked (bool, optional): Whether to include revoked API keys. Defaults to True.
2503+
2504+
Returns:
2505+
List[ApiKey]: A list of ApiKey objects.
2506+
"""
2507+
return ApiKey.get_api_keys(self, include_expired)
2508+
2509+
def get_api_key(self, api_key_id: str) -> Optional[ApiKey]:
2510+
"""Retrieves a single API key by its ID.
2511+
2512+
Args:
2513+
api_key_id (str): The unique ID of the API key.
2514+
2515+
Returns:
2516+
Optional[ApiKey]: The corresponding ApiKey object if found, otherwise None.
2517+
"""
2518+
return ApiKey.get_api_key(self, api_key_id)

libs/labelbox/src/labelbox/orm/model.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class Field:
2929
These `Comparison` objects can then be used for filtering:
3030
>>> project = client.get_projects(comparison)
3131
32-
Also exposes the ordering property used for sorting:
33-
>>> labels = project.labels(order_by=Label.label.asc)
34-
3532
Attributes:
3633
field_type (Field.Type): The type of the field.
3734
name (str): name that the attribute has in client-side Python objects

libs/labelbox/src/labelbox/schema/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
import labelbox.schema.ontology_kind
2828
import labelbox.schema.project_overview
2929
import labelbox.schema.taskstatus
30+
import labelbox.schema.api_key
31+
import labelbox.schema.timeunit

0 commit comments

Comments
 (0)