blaxel 0.2.1rc78__py3-none-any.whl → 0.2.2rc79__py3-none-any.whl

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.
@@ -10,6 +10,7 @@ from ..client.api.compute.get_sandbox import asyncio as get_sandbox
10
10
  from ..client.api.compute.list_sandboxes import asyncio as list_sandboxes
11
11
  from ..client.client import client
12
12
  from ..client.models import Metadata, Runtime, Sandbox, SandboxSpec
13
+ from ..client.types import UNSET
13
14
  from .filesystem import SandboxFileSystem
14
15
  from .network import SandboxNetwork
15
16
  from .preview import SandboxPreviews
@@ -76,13 +77,19 @@ class SandboxInstance:
76
77
  default_image = "blaxel/prod-base:latest"
77
78
  default_memory = 4096
78
79
 
79
- # Handle SandboxCreateConfiguration or simple dict with name/image/memory keys
80
- if sandbox is None or isinstance(sandbox, (SandboxCreateConfiguration, dict)) and (
81
- not isinstance(sandbox, Sandbox) and (
82
- sandbox is None or
83
- 'name' in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__) or
84
- 'image' in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__) or
85
- 'memory' in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__)
80
+ # Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports keys
81
+ if (
82
+ sandbox is None
83
+ or isinstance(sandbox, SandboxCreateConfiguration | dict)
84
+ and (
85
+ not isinstance(sandbox, Sandbox)
86
+ and (
87
+ sandbox is None
88
+ or "name" in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__)
89
+ or "image" in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__)
90
+ or "memory" in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__)
91
+ or "ports" in (sandbox if isinstance(sandbox, dict) else sandbox.__dict__)
92
+ )
86
93
  )
87
94
  ):
88
95
  if sandbox is None:
@@ -94,11 +101,14 @@ class SandboxInstance:
94
101
  name = sandbox.name or default_name
95
102
  image = sandbox.image or default_image
96
103
  memory = sandbox.memory or default_memory
104
+ ports = sandbox._normalize_ports() or UNSET
97
105
 
98
106
  # Create full Sandbox object
99
107
  sandbox = Sandbox(
100
108
  metadata=Metadata(name=name),
101
- spec=SandboxSpec(runtime=Runtime(image=image, memory=memory, generation="mk3"))
109
+ spec=SandboxSpec(
110
+ runtime=Runtime(image=image, memory=memory, ports=ports, generation="mk3")
111
+ ),
102
112
  )
103
113
  else:
104
114
  # Handle existing Sandbox object or dict conversion
@@ -107,7 +117,7 @@ class SandboxInstance:
107
117
 
108
118
  # Set defaults for missing fields
109
119
  if not sandbox.metadata:
110
- sandbox.metadata = Metadata(name=uuid.uuid4().hex.replace('-', ''))
120
+ sandbox.metadata = Metadata(name=uuid.uuid4().hex.replace("-", ""))
111
121
  if not sandbox.spec:
112
122
  sandbox.spec = SandboxSpec(runtime=Runtime(image=default_image))
113
123
  if not sandbox.spec.runtime:
@@ -154,10 +164,10 @@ class SandboxInstance:
154
164
  if isinstance(sandbox, SandboxCreateConfiguration):
155
165
  name = sandbox.name
156
166
  elif isinstance(sandbox, dict):
157
- if 'name' in sandbox:
158
- name = sandbox['name']
159
- elif 'metadata' in sandbox and isinstance(sandbox['metadata'], dict):
160
- name = sandbox['metadata'].get('name')
167
+ if "name" in sandbox:
168
+ name = sandbox["name"]
169
+ elif "metadata" in sandbox and isinstance(sandbox["metadata"], dict):
170
+ name = sandbox["metadata"].get("name")
161
171
  else:
162
172
  # If no name provided, we can't check if it exists, so create new
163
173
  return await cls.create(sandbox)
@@ -1,7 +1,8 @@
1
1
  from datetime import datetime
2
- from typing import Any, Dict, Optional
2
+ from typing import Any, Dict, List, Optional, Union
3
3
 
4
- from ..client.models import Sandbox
4
+ from ..client.models import Port, Sandbox
5
+ from ..client.types import UNSET
5
6
 
6
7
 
7
8
  class SessionCreateOptions:
@@ -105,15 +106,18 @@ class CopyResponse:
105
106
 
106
107
  class SandboxCreateConfiguration:
107
108
  """Simplified configuration for creating sandboxes with default values."""
109
+
108
110
  def __init__(
109
111
  self,
110
112
  name: Optional[str] = None,
111
113
  image: Optional[str] = None,
112
114
  memory: Optional[int] = None,
115
+ ports: Optional[Union[List[Port], List[Dict[str, Any]]]] = None,
113
116
  ):
114
117
  self.name = name
115
118
  self.image = image
116
119
  self.memory = memory
120
+ self.ports = ports
117
121
 
118
122
  @classmethod
119
123
  def from_dict(cls, data: Dict[str, Any]) -> "SandboxCreateConfiguration":
@@ -121,4 +125,28 @@ class SandboxCreateConfiguration:
121
125
  name=data.get("name"),
122
126
  image=data.get("image"),
123
127
  memory=data.get("memory"),
128
+ ports=data.get("ports"),
124
129
  )
130
+
131
+ def _normalize_ports(self) -> Optional[List[Port]]:
132
+ """Convert ports to Port objects with default protocol HTTP if not specified."""
133
+ if not self.ports:
134
+ return None
135
+
136
+ port_objects = []
137
+ for port in self.ports:
138
+ if isinstance(port, Port):
139
+ # If it's already a Port object, ensure protocol defaults to HTTP
140
+ if port.protocol is UNSET or not port.protocol:
141
+ port.protocol = "HTTP"
142
+ port_objects.append(port)
143
+ elif isinstance(port, dict):
144
+ # Convert dict to Port object with HTTP as default protocol
145
+ port_dict = port.copy()
146
+ if "protocol" not in port_dict or not port_dict["protocol"]:
147
+ port_dict["protocol"] = "HTTP"
148
+ port_objects.append(Port.from_dict(port_dict))
149
+ else:
150
+ raise ValueError(f"Invalid port type: {type(port)}. Expected Port object or dict.")
151
+
152
+ return port_objects
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blaxel
3
- Version: 0.2.1rc78
3
+ Version: 0.2.2rc79
4
4
  Summary: Blaxel - AI development platform SDK
5
5
  Project-URL: Homepage, https://blaxel.ai
6
6
  Project-URL: Documentation, https://docs.blaxel.ai
@@ -310,9 +310,9 @@ blaxel/core/sandbox/filesystem.py,sha256=dyIvDdlPZO0ijD6mXXX8Yl0t75VijQ6_uMz_9rJ
310
310
  blaxel/core/sandbox/network.py,sha256=P5jLd4AAg1zgyIK4qGWvZaDZ5BzIcxRx2ffz_JLsLMI,357
311
311
  blaxel/core/sandbox/preview.py,sha256=M6FulOxPghUBpb5fLxu1Rd3ekLeCbZ_dgt4s1X2Cneo,5354
312
312
  blaxel/core/sandbox/process.py,sha256=7zEngDTs2XiNsMm9TZ4lEDUiRpS3af8dw60pEvRuHDY,8357
313
- blaxel/core/sandbox/sandbox.py,sha256=4sG_i_VcuGx_cKEGMY-2eUUuGmtQBYMNIToL7YDuluM,8151
313
+ blaxel/core/sandbox/sandbox.py,sha256=3eJSWG0Y0jJsi1B5PK8BIvAEw-p0kP03vfUruYqAP14,8484
314
314
  blaxel/core/sandbox/session.py,sha256=4SH1tyXcQ9UqJx4lMwxAlp7x9Te_anDrdSEG6AlNkvU,4496
315
- blaxel/core/sandbox/types.py,sha256=yaKkp5Sn0b4Ri2_ZbdEjXuA-rjo2_DfDIHYz-cueZCA,3564
315
+ blaxel/core/sandbox/types.py,sha256=ylvwCnqNXMtCrGaJ-saMwi1Tz9ky_5phnpwmx4HNwOI,4775
316
316
  blaxel/core/sandbox/client/__init__.py,sha256=N26bD5o1jsTb48oExow6Rgivd8ylaU9jaWZfZsVilP8,128
317
317
  blaxel/core/sandbox/client/client.py,sha256=tcP8cJ4Q3dV9aB3yQ01dDXO-ekfsa3WGGFz4DQAEf8I,7079
318
318
  blaxel/core/sandbox/client/errors.py,sha256=gO8GBmKqmSNgAg-E5oT-oOyxztvp7V_6XG7OUTT15q0,546
@@ -402,7 +402,7 @@ blaxel/telemetry/instrumentation/map.py,sha256=PCzZJj39yiYVYJrxLBNP-NW-tjjYyTijw
402
402
  blaxel/telemetry/instrumentation/utils.py,sha256=KInMYZH-mu9_wvetmf0EmgrfN3Sw8IWk2Y95v2u90_U,1901
403
403
  blaxel/telemetry/log/log.py,sha256=RvQByRjZMoP_dRaAZu8oK6DTegsHs-xV4W-UIqis6CA,2461
404
404
  blaxel/telemetry/log/logger.py,sha256=NPAS3g82ryROjvc_DEZaTIfrcehoLEZoP-JkLxADxc0,4113
405
- blaxel-0.2.1rc78.dist-info/METADATA,sha256=r9IaM_vYSHVywuvDayI47ZwwxFDKCtLXlqGlogLKHps,9879
406
- blaxel-0.2.1rc78.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
407
- blaxel-0.2.1rc78.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
408
- blaxel-0.2.1rc78.dist-info/RECORD,,
405
+ blaxel-0.2.2rc79.dist-info/METADATA,sha256=Riq57nznlw3GBF4YKj_dpKtKdKbYg9jXxVR07J85SXE,9879
406
+ blaxel-0.2.2rc79.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
407
+ blaxel-0.2.2rc79.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
408
+ blaxel-0.2.2rc79.dist-info/RECORD,,