runcloud-sdk 0.9.0__tar.gz → 0.11.0__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.
Files changed (20) hide show
  1. {runcloud_sdk-0.9.0/runcloud_sdk.egg-info → runcloud_sdk-0.11.0}/PKG-INFO +1 -1
  2. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/pyproject.toml +1 -1
  3. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/client.py +32 -2
  4. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0/runcloud_sdk.egg-info}/PKG-INFO +1 -1
  5. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/tests/test_sdk.py +35 -0
  6. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/LICENSE +0 -0
  7. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/README.md +0 -0
  8. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/__init__.py +0 -0
  9. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/__init__.py +0 -0
  10. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/blaxel.py +0 -0
  11. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/daytona.py +0 -0
  12. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/e2b.py +0 -0
  13. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/modal.py +0 -0
  14. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/sprites.py +0 -0
  15. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud/compat/vercel.py +0 -0
  16. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud_sdk.egg-info/SOURCES.txt +0 -0
  17. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud_sdk.egg-info/dependency_links.txt +0 -0
  18. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud_sdk.egg-info/requires.txt +0 -0
  19. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/runcloud_sdk.egg-info/top_level.txt +0 -0
  20. {runcloud_sdk-0.9.0 → runcloud_sdk-0.11.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: runcloud-sdk
3
- Version: 0.9.0
3
+ Version: 0.11.0
4
4
  Summary: Python SDK for run.cloud, including sandbox-provider compatibility adapters
5
5
  Author: Newly
6
6
  License-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "runcloud-sdk"
3
- version = "0.9.0"
3
+ version = "0.11.0"
4
4
  description = "Python SDK for run.cloud, including sandbox-provider compatibility adapters"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"
@@ -354,7 +354,11 @@ class Client:
354
354
  timeout_seconds: Optional[int] = None,
355
355
  region: Optional[str] = None,
356
356
  name: Optional[str] = None,
357
+ tags: Optional[dict[str, str]] = None,
358
+ on_timeout: Optional[str] = None,
357
359
  ) -> "Sandbox":
360
+ """``on_timeout="destroy"`` destroys the sandbox when ``timeout_seconds``
361
+ runs out instead of parking it; use it for throwaway work."""
358
362
  values = {
359
363
  "image": image,
360
364
  "cpu": cpu,
@@ -364,6 +368,8 @@ class Client:
364
368
  "timeoutSeconds": timeout_seconds,
365
369
  "region": region,
366
370
  "name": name,
371
+ "tags": tags,
372
+ "onTimeout": on_timeout,
367
373
  }
368
374
  body = {key: value for key, value in values.items() if value is not None}
369
375
  return Sandbox(self, self.request("POST", "/run-cloud/sandboxes", body))
@@ -373,15 +379,20 @@ class Client:
373
379
  return Sandbox(self, self.request("GET", f"/run-cloud/sandboxes/{sid}"))
374
380
 
375
381
  def list(
376
- self, state: Optional[str] = None, name: Optional[str] = None
382
+ self,
383
+ state: Optional[str] = None,
384
+ name: Optional[str] = None,
385
+ tags: Optional[dict[str, str]] = None,
377
386
  ) -> list["Sandbox"]:
378
- # Both filters are applied server-side, so finding a sandbox by the name
387
+ # Every filter is applied server-side, so finding a sandbox by the name
379
388
  # you gave it does not mean paging the whole fleet and matching locally.
389
+ # Repeated `tag` params are ANDed together.
380
390
  filters = [
381
391
  (key, value)
382
392
  for key, value in (("state", state), ("name", name))
383
393
  if value
384
394
  ]
395
+ filters.extend(("tag", f"{key}:{value}") for key, value in (tags or {}).items())
385
396
  query = "?" + urllib.parse.urlencode(filters) if filters else ""
386
397
  payload = self.request("GET", "/run-cloud/sandboxes" + query) or {}
387
398
  return [Sandbox(self, item) for item in payload.get("items", [])]
@@ -401,6 +412,25 @@ class Sandbox:
401
412
  def name(self) -> str:
402
413
  return str(self._data.get("name") or "")
403
414
 
415
+ @property
416
+ def tags(self) -> dict[str, str]:
417
+ value = self._data.get("tags")
418
+ return dict(value) if isinstance(value, dict) else {}
419
+
420
+ def set_tags(self, tags: dict[str, Optional[str]]) -> "Sandbox":
421
+ """Merge tags into this sandbox. A None value deletes that key.
422
+
423
+ Tags survive the sandbox's destruction, so they stay usable for
424
+ attribution and support long after the sandbox is gone.
425
+ """
426
+ sid = urllib.parse.quote(self.id, safe="")
427
+ updated = self._client.request(
428
+ "PATCH", f"/run-cloud/sandboxes/{sid}/tags", {"tags": tags}
429
+ )
430
+ if isinstance(updated, dict) and isinstance(updated.get("tags"), dict):
431
+ self._data["tags"] = updated["tags"]
432
+ return self
433
+
404
434
  def refresh(self) -> "Sandbox":
405
435
  self._data = self._client.request(
406
436
  "GET", f"/run-cloud/sandboxes/{urllib.parse.quote(self.id, safe='')}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: runcloud-sdk
3
- Version: 0.9.0
3
+ Version: 0.11.0
4
4
  Summary: Python SDK for run.cloud, including sandbox-provider compatibility adapters
5
5
  Author: Newly
6
6
  License-Expression: Apache-2.0
@@ -416,6 +416,41 @@ class SDKTests(unittest.TestCase):
416
416
  self.assertIsNone(delete_request.get_header("Content-type"))
417
417
  self.assertEqual(post_request.get_header("Content-type"), "application/json")
418
418
 
419
+ def test_tags_are_sent_on_create_and_exposed_on_the_record(self):
420
+ box = self.client.create(tags={"newly.session": "sess-1"})
421
+ method, path, body = self.recorder.calls[0]
422
+ self.assertEqual((method, path), ("POST", "/run-cloud/sandboxes"))
423
+ self.assertEqual(body["tags"], {"newly.session": "sess-1"})
424
+ # The fixture carries no tags, so an untagged payload must read as {}.
425
+ self.assertEqual(box.tags, {})
426
+
427
+ def test_on_timeout_is_sent_only_when_given(self):
428
+ self.client.create(on_timeout="destroy")
429
+ self.client.create()
430
+ self.assertEqual(self.recorder.calls[0][2]["onTimeout"], "destroy")
431
+ self.assertNotIn("onTimeout", self.recorder.calls[1][2])
432
+
433
+ def test_create_omits_tags_when_none_are_given(self):
434
+ self.client.create()
435
+ _, _, body = self.recorder.calls[0]
436
+ self.assertNotIn("tags", body)
437
+
438
+ def test_list_ands_repeated_tag_filters(self):
439
+ self.client.list(state="running", tags={"newly.role": "agent", "env": "dev"})
440
+ _, path, _ = self.recorder.calls[0]
441
+ self.assertEqual(
442
+ path,
443
+ "/run-cloud/sandboxes?state=running&tag=newly.role%3Aagent&tag=env%3Adev",
444
+ )
445
+
446
+ def test_set_tags_patches_and_keeps_null_delete_markers(self):
447
+ box = self.client.create()
448
+ box.set_tags({"newly.role": "agent", "gone": None})
449
+ method, path, body = self.recorder.calls[-1]
450
+ self.assertEqual(method, "PATCH")
451
+ self.assertEqual(path, "/run-cloud/sandboxes/sb_python/tags")
452
+ self.assertEqual(body, {"tags": {"newly.role": "agent", "gone": None}})
453
+
419
454
 
420
455
  class CredentialTests(unittest.TestCase):
421
456
  def setUp(self):
File without changes
File without changes
File without changes