e2b-code-interpreter 2.3.0__tar.gz → 2.4.1__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.
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/PKG-INFO +2 -2
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/code_interpreter_async.py +106 -10
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/code_interpreter_sync.py +105 -9
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/pyproject.toml +4 -4
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/LICENSE +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/README.md +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/__init__.py +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/charts.py +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/constants.py +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/exceptions.py +0 -0
- {e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2b-code-interpreter
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.1
|
|
4
4
|
Summary: E2B Code Interpreter - Stateful code execution
|
|
5
5
|
Home-page: https://e2b.dev/
|
|
6
6
|
License: MIT
|
|
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Requires-Dist: attrs (>=21.3.0)
|
|
17
|
-
Requires-Dist: e2b (>=2.
|
|
17
|
+
Requires-Dist: e2b (>=2.7.0,<3.0.0)
|
|
18
18
|
Requires-Dist: httpx (>=0.20.0,<1.0.0)
|
|
19
19
|
Project-URL: Bug Tracker, https://github.com/e2b-dev/code-interpreter/issues
|
|
20
20
|
Project-URL: Repository, https://github.com/e2b-dev/code-interpreter/tree/main/python
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import httpx
|
|
3
3
|
|
|
4
|
-
from typing import Optional, Dict, overload, Union, Literal
|
|
4
|
+
from typing import Optional, Dict, overload, Union, Literal, List
|
|
5
5
|
from httpx import AsyncClient
|
|
6
6
|
|
|
7
7
|
from e2b import (
|
|
@@ -190,12 +190,15 @@ class AsyncSandbox(BaseAsyncSandbox):
|
|
|
190
190
|
timeout = None if timeout == 0 else (timeout or DEFAULT_TIMEOUT)
|
|
191
191
|
request_timeout = request_timeout or self.connection_config.request_timeout
|
|
192
192
|
context_id = context.id if context else None
|
|
193
|
-
|
|
194
|
-
headers: Dict[str, str] = {}
|
|
195
|
-
if self._envd_access_token:
|
|
196
|
-
headers = {"X-Access-Token": self._envd_access_token}
|
|
197
|
-
|
|
198
193
|
try:
|
|
194
|
+
headers = {
|
|
195
|
+
"Content-Type": "application/json",
|
|
196
|
+
}
|
|
197
|
+
if self._envd_access_token:
|
|
198
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
199
|
+
if self.traffic_access_token:
|
|
200
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
201
|
+
|
|
199
202
|
async with self._client.stream(
|
|
200
203
|
"POST",
|
|
201
204
|
f"{self._jupyter_url}/execute",
|
|
@@ -253,11 +256,13 @@ class AsyncSandbox(BaseAsyncSandbox):
|
|
|
253
256
|
if cwd:
|
|
254
257
|
data["cwd"] = cwd
|
|
255
258
|
|
|
256
|
-
headers: Dict[str, str] = {}
|
|
257
|
-
if self._envd_access_token:
|
|
258
|
-
headers = {"X-Access-Token": self._envd_access_token}
|
|
259
|
-
|
|
260
259
|
try:
|
|
260
|
+
headers = {
|
|
261
|
+
"Content-Type": "application/json",
|
|
262
|
+
}
|
|
263
|
+
if self.traffic_access_token:
|
|
264
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
265
|
+
|
|
261
266
|
response = await self._client.post(
|
|
262
267
|
f"{self._jupyter_url}/contexts",
|
|
263
268
|
headers=headers,
|
|
@@ -273,3 +278,94 @@ class AsyncSandbox(BaseAsyncSandbox):
|
|
|
273
278
|
return Context.from_json(data)
|
|
274
279
|
except httpx.TimeoutException:
|
|
275
280
|
raise format_request_timeout_error()
|
|
281
|
+
|
|
282
|
+
async def remove_code_context(
|
|
283
|
+
self,
|
|
284
|
+
context: Union[Context, str],
|
|
285
|
+
) -> None:
|
|
286
|
+
"""
|
|
287
|
+
Removes a context.
|
|
288
|
+
|
|
289
|
+
:param context: Context to remove. Can be a Context object or a context ID string.
|
|
290
|
+
|
|
291
|
+
:return: None
|
|
292
|
+
"""
|
|
293
|
+
context_id = context.id if isinstance(context, Context) else context
|
|
294
|
+
|
|
295
|
+
try:
|
|
296
|
+
headers = {
|
|
297
|
+
"Content-Type": "application/json",
|
|
298
|
+
}
|
|
299
|
+
if self.traffic_access_token:
|
|
300
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
301
|
+
|
|
302
|
+
response = await self._client.delete(
|
|
303
|
+
f"{self._jupyter_url}/contexts/{context_id}",
|
|
304
|
+
headers=headers,
|
|
305
|
+
timeout=self.connection_config.request_timeout,
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
err = await aextract_exception(response)
|
|
309
|
+
if err:
|
|
310
|
+
raise err
|
|
311
|
+
except httpx.TimeoutException:
|
|
312
|
+
raise format_request_timeout_error()
|
|
313
|
+
|
|
314
|
+
async def list_code_contexts(self) -> List[Context]:
|
|
315
|
+
"""
|
|
316
|
+
List all contexts.
|
|
317
|
+
|
|
318
|
+
:return: List of contexts.
|
|
319
|
+
"""
|
|
320
|
+
try:
|
|
321
|
+
headers = {
|
|
322
|
+
"Content-Type": "application/json",
|
|
323
|
+
}
|
|
324
|
+
if self.traffic_access_token:
|
|
325
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
326
|
+
|
|
327
|
+
response = await self._client.get(
|
|
328
|
+
f"{self._jupyter_url}/contexts",
|
|
329
|
+
headers=headers,
|
|
330
|
+
timeout=self.connection_config.request_timeout,
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
err = await aextract_exception(response)
|
|
334
|
+
if err:
|
|
335
|
+
raise err
|
|
336
|
+
|
|
337
|
+
data = response.json()
|
|
338
|
+
return [Context.from_json(context_data) for context_data in data]
|
|
339
|
+
except httpx.TimeoutException:
|
|
340
|
+
raise format_request_timeout_error()
|
|
341
|
+
|
|
342
|
+
async def restart_code_context(
|
|
343
|
+
self,
|
|
344
|
+
context: Union[Context, str],
|
|
345
|
+
) -> None:
|
|
346
|
+
"""
|
|
347
|
+
Restart a context.
|
|
348
|
+
|
|
349
|
+
:param context: Context to restart. Can be a Context object or a context ID string.
|
|
350
|
+
|
|
351
|
+
:return: None
|
|
352
|
+
"""
|
|
353
|
+
context_id = context.id if isinstance(context, Context) else context
|
|
354
|
+
try:
|
|
355
|
+
headers = {
|
|
356
|
+
"Content-Type": "application/json",
|
|
357
|
+
}
|
|
358
|
+
if self.traffic_access_token:
|
|
359
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
360
|
+
|
|
361
|
+
response = await self._client.post(
|
|
362
|
+
f"{self._jupyter_url}/contexts/{context_id}/restart",
|
|
363
|
+
headers=headers,
|
|
364
|
+
timeout=self.connection_config.request_timeout,
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
err = await aextract_exception(response)
|
|
368
|
+
if err:
|
|
369
|
+
raise err
|
|
370
|
+
except httpx.TimeoutException:
|
|
371
|
+
raise format_request_timeout_error()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import httpx
|
|
3
3
|
|
|
4
|
-
from typing import Optional, Dict, overload, Literal, Union
|
|
4
|
+
from typing import Optional, Dict, overload, Literal, Union, List
|
|
5
5
|
from httpx import Client
|
|
6
6
|
from e2b import Sandbox as BaseSandbox, InvalidArgumentException
|
|
7
7
|
|
|
@@ -188,11 +188,13 @@ class Sandbox(BaseSandbox):
|
|
|
188
188
|
request_timeout = request_timeout or self.connection_config.request_timeout
|
|
189
189
|
context_id = context.id if context else None
|
|
190
190
|
|
|
191
|
-
headers: Dict[str, str] = {}
|
|
192
|
-
if self._envd_access_token:
|
|
193
|
-
headers = {"X-Access-Token": self._envd_access_token}
|
|
194
|
-
|
|
195
191
|
try:
|
|
192
|
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
|
193
|
+
if self._envd_access_token:
|
|
194
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
195
|
+
if self.traffic_access_token:
|
|
196
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
197
|
+
|
|
196
198
|
with self._client.stream(
|
|
197
199
|
"POST",
|
|
198
200
|
f"{self._jupyter_url}/execute",
|
|
@@ -250,11 +252,13 @@ class Sandbox(BaseSandbox):
|
|
|
250
252
|
if cwd:
|
|
251
253
|
data["cwd"] = cwd
|
|
252
254
|
|
|
253
|
-
headers: Dict[str, str] = {}
|
|
254
|
-
if self._envd_access_token:
|
|
255
|
-
headers = {"X-Access-Token": self._envd_access_token}
|
|
256
|
-
|
|
257
255
|
try:
|
|
256
|
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
|
257
|
+
if self._envd_access_token:
|
|
258
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
259
|
+
if self.traffic_access_token:
|
|
260
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
261
|
+
|
|
258
262
|
response = self._client.post(
|
|
259
263
|
f"{self._jupyter_url}/contexts",
|
|
260
264
|
json=data,
|
|
@@ -270,3 +274,95 @@ class Sandbox(BaseSandbox):
|
|
|
270
274
|
return Context.from_json(data)
|
|
271
275
|
except httpx.TimeoutException:
|
|
272
276
|
raise format_request_timeout_error()
|
|
277
|
+
|
|
278
|
+
def remove_code_context(
|
|
279
|
+
self,
|
|
280
|
+
context: Union[Context, str],
|
|
281
|
+
) -> None:
|
|
282
|
+
"""
|
|
283
|
+
Removes a context.
|
|
284
|
+
|
|
285
|
+
:param context: Context to remove. Can be a Context object or a context ID string.
|
|
286
|
+
|
|
287
|
+
:return: None
|
|
288
|
+
"""
|
|
289
|
+
context_id = context.id if isinstance(context, Context) else context
|
|
290
|
+
|
|
291
|
+
try:
|
|
292
|
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
|
293
|
+
if self._envd_access_token:
|
|
294
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
295
|
+
if self.traffic_access_token:
|
|
296
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
297
|
+
|
|
298
|
+
response = self._client.delete(
|
|
299
|
+
f"{self._jupyter_url}/contexts/{context_id}",
|
|
300
|
+
headers=headers,
|
|
301
|
+
timeout=self.connection_config.request_timeout,
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
err = extract_exception(response)
|
|
305
|
+
if err:
|
|
306
|
+
raise err
|
|
307
|
+
except httpx.TimeoutException:
|
|
308
|
+
raise format_request_timeout_error()
|
|
309
|
+
|
|
310
|
+
def list_code_contexts(self) -> List[Context]:
|
|
311
|
+
"""
|
|
312
|
+
List all contexts.
|
|
313
|
+
|
|
314
|
+
:return: List of contexts.
|
|
315
|
+
"""
|
|
316
|
+
try:
|
|
317
|
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
|
318
|
+
if self._envd_access_token:
|
|
319
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
320
|
+
if self.traffic_access_token:
|
|
321
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
322
|
+
|
|
323
|
+
response = self._client.get(
|
|
324
|
+
f"{self._jupyter_url}/contexts",
|
|
325
|
+
headers=headers,
|
|
326
|
+
timeout=self.connection_config.request_timeout,
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
err = extract_exception(response)
|
|
330
|
+
if err:
|
|
331
|
+
raise err
|
|
332
|
+
|
|
333
|
+
data = response.json()
|
|
334
|
+
return [Context.from_json(context_data) for context_data in data]
|
|
335
|
+
except httpx.TimeoutException:
|
|
336
|
+
raise format_request_timeout_error()
|
|
337
|
+
|
|
338
|
+
def restart_code_context(
|
|
339
|
+
self,
|
|
340
|
+
context: Union[Context, str],
|
|
341
|
+
) -> None:
|
|
342
|
+
"""
|
|
343
|
+
Restart a context.
|
|
344
|
+
|
|
345
|
+
:param context: Context to restart. Can be a Context object or a context ID string.
|
|
346
|
+
|
|
347
|
+
:return: None
|
|
348
|
+
"""
|
|
349
|
+
context_id = context.id if isinstance(context, Context) else context
|
|
350
|
+
|
|
351
|
+
try:
|
|
352
|
+
headers: Dict[str, str] = {"Content-Type": "application/json"}
|
|
353
|
+
if self._envd_access_token:
|
|
354
|
+
headers["X-Access-Token"] = self._envd_access_token
|
|
355
|
+
if self.traffic_access_token:
|
|
356
|
+
headers["E2B-Traffic-Access-Token"] = self.traffic_access_token
|
|
357
|
+
|
|
358
|
+
response = self._client.post(
|
|
359
|
+
f"{self._jupyter_url}/contexts/{context_id}/restart",
|
|
360
|
+
headers=headers,
|
|
361
|
+
timeout=self.connection_config.request_timeout,
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
err = extract_exception(response)
|
|
365
|
+
if err:
|
|
366
|
+
raise err
|
|
367
|
+
except httpx.TimeoutException:
|
|
368
|
+
raise format_request_timeout_error()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "e2b-code-interpreter"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.4.1"
|
|
4
4
|
description = "E2B Code Interpreter - Stateful code execution"
|
|
5
5
|
authors = ["e2b <hello@e2b.dev>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -14,13 +14,13 @@ python = "^3.9"
|
|
|
14
14
|
|
|
15
15
|
httpx = ">=0.20.0, <1.0.0"
|
|
16
16
|
attrs = ">=21.3.0"
|
|
17
|
-
e2b = "^2.
|
|
17
|
+
e2b = "^2.7.0"
|
|
18
18
|
|
|
19
19
|
[tool.poetry.group.dev.dependencies]
|
|
20
|
-
pytest = "^
|
|
20
|
+
pytest = "^8.2.0"
|
|
21
21
|
python-dotenv = "^1.0.0"
|
|
22
22
|
pytest-dotenv = "^0.5.2"
|
|
23
|
-
pytest-asyncio = "^0.
|
|
23
|
+
pytest-asyncio = "^0.24.0"
|
|
24
24
|
pytest-xdist = "^3.6.1"
|
|
25
25
|
pydoc-markdown = "^4.8.2"
|
|
26
26
|
matplotlib = "^3.8.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{e2b_code_interpreter-2.3.0 → e2b_code_interpreter-2.4.1}/e2b_code_interpreter/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|