Skip to content

Commit c8d968e

Browse files
committed
Add beta
1 parent 4434222 commit c8d968e

File tree

6 files changed

+373
-278
lines changed

6 files changed

+373
-278
lines changed

packages/python-sdk/e2b/api/compatibility/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/python-sdk/e2b/api/compatibility/modified_get_v2_sandboxes.py

Lines changed: 0 additions & 228 deletions
This file was deleted.

packages/python-sdk/e2b/sandbox/sandbox_api.py

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from dataclasses import dataclass
2-
from typing import Optional, Dict
2+
from typing import Optional, Dict, Union, Unpack
33
from datetime import datetime
44

5-
from e2b.api.client.models import SandboxState
5+
from e2b import ConnectionConfig
6+
from e2b.api.client.models import SandboxState, SandboxDetail, ListedSandbox
7+
from e2b.connection_config import ApiParams
68

79

810
@dataclass
@@ -23,33 +25,64 @@ class SandboxInfo:
2325
"""Sandbox start time."""
2426
end_at: datetime
2527
"""Sandbox expiration date."""
26-
envd_version: Optional[str]
28+
state: SandboxState
29+
"""Sandbox state."""
30+
cpu_count: int
31+
"""Sandbox CPU count."""
32+
memory_mb: int
33+
"""Sandbox Memory size in MiB."""
34+
_envd_version: Optional[str]
2735
"""Envd version."""
2836
_envd_access_token: Optional[str]
2937
"""Envd access token."""
3038

39+
@classmethod
40+
def _from_sandbox_data(
41+
cls,
42+
sandbox: Union[ListedSandbox, SandboxDetail],
43+
envd_version: Optional[str] = None,
44+
envd_access_token: Optional[str] = None,
45+
sandbox_domain: Optional[str] = None,
46+
):
47+
return cls(
48+
sandbox_domain=sandbox_domain,
49+
sandbox_id=sandbox.sandbox_id,
50+
template_id=sandbox.template_id,
51+
name=(sandbox.alias if isinstance(sandbox.alias, str) else None),
52+
metadata=(sandbox.metadata if isinstance(sandbox.metadata, dict) else {}),
53+
started_at=sandbox.started_at,
54+
end_at=sandbox.end_at,
55+
state=sandbox.state,
56+
cpu_count=sandbox.cpu_count,
57+
memory_mb=sandbox.memory_mb,
58+
_envd_version=envd_version,
59+
_envd_access_token=envd_access_token,
60+
)
3161

32-
@dataclass
33-
class ListedSandbox:
34-
"""Information about a sandbox."""
62+
@classmethod
63+
def _from_listed_sandbox(cls, listed_sandbox: ListedSandbox):
64+
return cls._from_sandbox_data(listed_sandbox)
3565

36-
sandbox_id: str
37-
"""Sandbox ID."""
38-
template_id: str
39-
"""Template ID."""
40-
name: Optional[str]
41-
"""Template Alias."""
42-
state: SandboxState
43-
"""Sandbox state."""
44-
cpu_count: int
45-
"""Sandbox CPU count."""
46-
memory_mb: int
47-
"""Sandbox Memory size in MB."""
48-
metadata: Dict[str, str]
49-
"""Saved sandbox metadata."""
50-
started_at: datetime
51-
"""Sandbox start time."""
52-
end_at: datetime
66+
@classmethod
67+
def _from_sandbox_detail(cls, sandbox_detail: SandboxDetail):
68+
return cls._from_sandbox_data(
69+
sandbox_detail,
70+
(
71+
sandbox_detail.envd_version
72+
if isinstance(sandbox_detail.envd_version, str)
73+
else None
74+
),
75+
(
76+
sandbox_detail.envd_access_token
77+
if isinstance(sandbox_detail.envd_access_token, str)
78+
else None
79+
),
80+
sandbox_domain=(
81+
sandbox_detail.domain
82+
if isinstance(sandbox_detail.domain, str)
83+
else None
84+
),
85+
)
5386

5487

5588
@dataclass
@@ -60,6 +93,14 @@ class SandboxQuery:
6093
"""Filter sandboxes by metadata."""
6194

6295

96+
@dataclass
97+
class SandboxQueryBeta(SandboxQuery):
98+
"""Query parameters for listing sandboxes."""
99+
100+
state: Optional[list[SandboxState]] = None
101+
"""Filter sandboxes by state."""
102+
103+
63104
@dataclass
64105
class SandboxMetrics:
65106
"""Sandbox metrics."""
@@ -78,3 +119,34 @@ class SandboxMetrics:
78119
"""Memory used in bytes."""
79120
timestamp: datetime
80121
"""Timestamp of the metric entry."""
122+
123+
124+
class SandboxPaginatorBase:
125+
def __init__(
126+
self,
127+
query: Optional[SandboxQueryBeta] = None,
128+
limit: Optional[int] = None,
129+
next_token: Optional[str] = None,
130+
**opts: Unpack[ApiParams],
131+
):
132+
self._config = ConnectionConfig(**opts)
133+
134+
self.query = query
135+
self.limit = limit
136+
137+
self._has_next = True
138+
self._next_token = next_token
139+
140+
@property
141+
def has_next(self) -> bool:
142+
"""
143+
Returns True if there are more items to fetch.
144+
"""
145+
return self._has_next
146+
147+
@property
148+
def next_token(self) -> Optional[str]:
149+
"""
150+
Returns the next token to use for pagination.
151+
"""
152+
return self._next_token

packages/python-sdk/e2b/sandbox_async/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async def connect(
265265
sandbox_id=sandbox_id,
266266
sandbox_domain=response.sandbox_domain,
267267
connection_config=connection_config,
268-
envd_version=response.envd_version,
268+
envd_version=response._envd_version,
269269
envd_access_token=envd_access_token,
270270
)
271271

0 commit comments

Comments
 (0)