Skip to content

Commit 25e2487

Browse files
committed
Simplify classes
1 parent 77997f1 commit 25e2487

6 files changed

Lines changed: 27 additions & 40 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from httpx import Limits
99

1010

11-
class SandboxSetup:
11+
class SandboxBase:
1212
_limits = Limits(
1313
max_keepalive_connections=40,
1414
max_connections=40,

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from abc import ABC
21
from dataclasses import dataclass
32
from typing import Optional, Dict
43
from datetime import datetime
54

6-
from httpx import Limits
7-
85
from e2b.api.client.models import SandboxState
96

107

@@ -81,11 +78,3 @@ class SandboxMetrics:
8178
"""Memory used in bytes."""
8279
timestamp: datetime
8380
"""Timestamp of the metric entry."""
84-
85-
86-
class SandboxApiBase(ABC):
87-
_limits = Limits(
88-
max_keepalive_connections=10,
89-
max_connections=20,
90-
keepalive_expiry=20,
91-
)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from e2b.connection_config import ConnectionConfig, ApiParams
1212
from e2b.envd.api import ENVD_API_HEALTH_ROUTE, ahandle_envd_api_exception
1313
from e2b.exceptions import format_request_timeout_error, SandboxException
14-
from e2b.sandbox.main import SandboxSetup
1514
from e2b.sandbox.sandbox_api import SandboxMetrics
1615
from e2b.sandbox.utils import class_method_variant
1716
from e2b.sandbox_async.filesystem.filesystem import Filesystem
@@ -46,7 +45,7 @@ class AsyncSandboxOpts(TypedDict):
4645
connection_config: ConnectionConfig
4746

4847

49-
class AsyncSandbox(SandboxSetup, SandboxApi):
48+
class AsyncSandbox(SandboxApi):
5049
"""
5150
E2B cloud sandbox is a secure and isolated cloud environment.
5251
@@ -195,7 +194,7 @@ async def create(
195194
envd_version = None
196195
envd_access_token = None
197196
else:
198-
response = await SandboxApi._create_sandbox(
197+
response = await cls._create_sandbox(
199198
template=template or cls.default_template,
200199
timeout=timeout or cls.default_sandbox_timeout,
201200
metadata=metadata,
@@ -251,7 +250,7 @@ async def connect(
251250
# Another code block
252251
same_sandbox = await AsyncSandbox.connect(sandbox_id)
253252
"""
254-
response = await SandboxApi._cls_get_info(sandbox_id, **opts)
253+
response = await cls._cls_get_info(sandbox_id, **opts)
255254

256255
sandbox_headers = {}
257256
envd_access_token = response._envd_access_token
@@ -314,7 +313,7 @@ async def kill(
314313
315314
:return: `True` if the sandbox was killed, `False` if the sandbox was not found
316315
"""
317-
return await SandboxApi._cls_kill(
316+
return await self._cls_kill(
318317
sandbox_id=self.sandbox_id,
319318
**self.connection_config.get_api_params(**opts),
320319
)
@@ -370,7 +369,7 @@ async def set_timeout( # type: ignore
370369
371370
:param timeout: Timeout for the sandbox in **seconds**
372371
"""
373-
await SandboxApi._cls_set_timeout(
372+
await self._cls_set_timeout(
374373
sandbox_id=self.sandbox_id,
375374
timeout=timeout,
376375
**self.connection_config.get_api_params(**opts),
@@ -413,7 +412,7 @@ async def get_info(
413412
:return: Sandbox info
414413
"""
415414

416-
return await SandboxApi._cls_get_info(
415+
return await self._cls_get_info(
417416
sandbox_id=self.sandbox_id,
418417
**self.connection_config.get_api_params(**opts),
419418
)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from packaging.version import Version
66
from typing_extensions import Unpack
77

8+
from e2b.sandbox.main import SandboxBase
89
from e2b.sandbox.sandbox_api import (
910
SandboxInfo,
10-
SandboxApiBase,
1111
SandboxQuery,
1212
ListedSandbox,
1313
SandboxMetrics,
@@ -31,7 +31,7 @@
3131
from e2b.api import handle_api_exception
3232

3333

34-
class SandboxApi(SandboxApiBase):
34+
class SandboxApi(SandboxBase):
3535
@classmethod
3636
async def list(
3737
cls,
@@ -59,7 +59,7 @@ async def list(
5959

6060
async with AsyncApiClient(
6161
config,
62-
limits=SandboxApiBase._limits,
62+
limits=cls._limits,
6363
) as api_client:
6464
res = await get_sandboxes.asyncio_detailed(
6565
client=api_client,
@@ -105,7 +105,7 @@ async def _cls_get_info(
105105

106106
async with AsyncApiClient(
107107
config,
108-
limits=SandboxApiBase._limits,
108+
limits=cls._limits,
109109
) as api_client:
110110
res = await get_sandboxes_sandbox_id.asyncio_detailed(
111111
sandbox_id,
@@ -146,7 +146,7 @@ async def _cls_kill(
146146

147147
async with AsyncApiClient(
148148
config,
149-
limits=SandboxApiBase._limits,
149+
limits=cls._limits,
150150
) as api_client:
151151
res = await delete_sandboxes_sandbox_id.asyncio_detailed(
152152
sandbox_id,
@@ -176,7 +176,7 @@ async def _cls_set_timeout(
176176

177177
async with AsyncApiClient(
178178
config,
179-
limits=SandboxApiBase._limits,
179+
limits=cls._limits,
180180
) as api_client:
181181
res = await post_sandboxes_sandbox_id_timeout.asyncio_detailed(
182182
sandbox_id,
@@ -202,7 +202,7 @@ async def _create_sandbox(
202202

203203
async with AsyncApiClient(
204204
config,
205-
limits=SandboxApiBase._limits,
205+
limits=cls._limits,
206206
) as api_client:
207207
res = await post_sandboxes.asyncio_detailed(
208208
body=NewSandbox(

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from e2b.connection_config import ConnectionConfig, ApiParams
1212
from e2b.envd.api import ENVD_API_HEALTH_ROUTE, handle_envd_api_exception
1313
from e2b.exceptions import SandboxException, format_request_timeout_error
14-
from e2b.sandbox.main import SandboxSetup
1514
from e2b.sandbox.sandbox_api import SandboxMetrics
1615
from e2b.sandbox.utils import class_method_variant
1716
from e2b.sandbox_sync.filesystem.filesystem import Filesystem
@@ -38,7 +37,7 @@ def pool(self):
3837
return self._pool
3938

4039

41-
class Sandbox(SandboxSetup, SandboxApi):
40+
class Sandbox(SandboxApi):
4241
"""
4342
E2B cloud sandbox is a secure and isolated cloud environment.
4443
@@ -124,7 +123,7 @@ def __init__(
124123
if debug:
125124
_sandbox_id = "debug_sandbox_id"
126125
elif _sandbox_id is not None:
127-
response = SandboxApi._cls_get_info(
126+
response = self._cls_get_info(
128127
_sandbox_id,
129128
**opts,
130129
)
@@ -140,7 +139,7 @@ def __init__(
140139
else:
141140
template = template or self.default_template
142141
timeout = timeout or self.default_sandbox_timeout
143-
response = SandboxApi._create_sandbox(
142+
response = self._create_sandbox(
144143
template=template,
145144
timeout=timeout,
146145
metadata=metadata,
@@ -307,7 +306,7 @@ def kill(
307306
308307
:return: `True` if the sandbox was killed, `False` if the sandbox was not found
309308
"""
310-
return SandboxApi._cls_kill(
309+
return self._cls_kill(
311310
sandbox_id=self.sandbox_id,
312311
**self.connection_config.get_api_params(**opts),
313312
)
@@ -365,7 +364,7 @@ def set_timeout(
365364
366365
"""
367366

368-
SandboxApi._cls_set_timeout(
367+
self._cls_set_timeout(
369368
sandbox_id=self.sandbox_id,
370369
timeout=timeout,
371370
**self.connection_config.get_api_params(**opts),
@@ -408,7 +407,7 @@ def get_info(
408407
409408
:return: Sandbox info
410409
"""
411-
return SandboxApi._cls_get_info(
410+
return self._cls_get_info(
412411
sandbox_id=self.sandbox_id,
413412
**self.connection_config.get_api_params(**opts),
414413
)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
from e2b.sandbox.sandbox_api import (
99
SandboxInfo,
10-
SandboxApiBase,
1110
SandboxQuery,
1211
ListedSandbox,
1312
SandboxMetrics,
1413
)
14+
from e2b.sandbox.main import SandboxBase
1515
from e2b.exceptions import TemplateException, SandboxException
1616
from e2b.api import ApiClient, SandboxCreateResponse
1717
from e2b.api.client.models import (
@@ -31,7 +31,7 @@
3131
from e2b.api import handle_api_exception
3232

3333

34-
class SandboxApi(SandboxApiBase):
34+
class SandboxApi(SandboxBase):
3535
@classmethod
3636
def list(
3737
cls,
@@ -59,7 +59,7 @@ def list(
5959

6060
with ApiClient(
6161
config,
62-
limits=SandboxApiBase._limits,
62+
limits=cls._limits,
6363
) as api_client:
6464
res = get_sandboxes.sync_detailed(client=api_client, metadata=metadata)
6565

@@ -102,7 +102,7 @@ def _cls_get_info(
102102

103103
with ApiClient(
104104
config,
105-
limits=SandboxApiBase._limits,
105+
limits=cls._limits,
106106
) as api_client:
107107
res = get_sandboxes_sandbox_id.sync_detailed(
108108
sandbox_id,
@@ -143,7 +143,7 @@ def _cls_kill(
143143

144144
with ApiClient(
145145
config,
146-
limits=SandboxApiBase._limits,
146+
limits=cls._limits,
147147
) as api_client:
148148
res = delete_sandboxes_sandbox_id.sync_detailed(
149149
sandbox_id,
@@ -173,7 +173,7 @@ def _cls_set_timeout(
173173

174174
with ApiClient(
175175
config,
176-
limits=SandboxApiBase._limits,
176+
limits=cls._limits,
177177
) as api_client:
178178
res = post_sandboxes_sandbox_id_timeout.sync_detailed(
179179
sandbox_id,
@@ -197,7 +197,7 @@ def _create_sandbox(
197197
) -> SandboxCreateResponse:
198198
config = ConnectionConfig(**opts)
199199

200-
with ApiClient(config, limits=SandboxApiBase._limits) as api_client:
200+
with ApiClient(config, limits=cls._limits) as api_client:
201201
res = post_sandboxes.sync_detailed(
202202
body=NewSandbox(
203203
template_id=template,

0 commit comments

Comments
 (0)