e2b-code-interpreter 0.0.2__tar.gz → 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: e2b-code-interpreter
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: E2B Code Interpreter - Stateful code execution
5
5
  Home-page: https://e2b.dev/
6
6
  License: Apache-2.0
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
14
14
  Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
- Requires-Dist: e2b (>=0.14.11)
17
+ Requires-Dist: e2b (>=0.17.0)
18
18
  Requires-Dist: pydantic (>1,<3)
19
19
  Requires-Dist: websocket-client (>=1.7.0,<2.0.0)
20
20
  Project-URL: Bug Tracker, https://github.com/e2b-dev/code-interpreter/issues
@@ -112,45 +112,3 @@ with CodeInterpreter() as sandbox:
112
112
  sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print, on_result=(lambda result: print(result.text)))
113
113
  ```
114
114
 
115
- ### Pre-installed Python packages inside the sandbox
116
-
117
- The full and always up-to-date list can be found in the [`requirements.txt`](https://github.com/e2b-dev/E2B/blob/stateful-code-interpreter/sandboxes/code-interpreter-stateful/requirements.txt) file.
118
-
119
- ```text
120
- # Jupyter server requirements
121
- jupyter-server==2.13.0
122
- ipykernel==6.29.3
123
- ipython==8.22.2
124
-
125
- # Other packages
126
- aiohttp==3.9.3
127
- beautifulsoup4==4.12.3
128
- bokeh==3.3.4
129
- gensim==4.3.2
130
- imageio==2.34.0
131
- joblib==1.3.2
132
- librosa==0.10.1
133
- matplotlib==3.8.3
134
- nltk==3.8.1
135
- numpy==1.26.4
136
- opencv-python==4.9.0.80
137
- openpyxl==3.1.2
138
- pandas==1.5.3
139
- plotly==5.19.0
140
- pytest==8.1.0
141
- python-docx==1.1.0
142
- pytz==2024.1
143
- requests==2.26.0
144
- scikit-image==0.22.0
145
- scikit-learn==1.4.1.post1
146
- scipy==1.12.0
147
- seaborn==0.13.2
148
- soundfile==0.12.1
149
- spacy==3.7.4
150
- textblob==0.18.0
151
- tornado==6.4
152
- urllib3==1.26.7
153
- xarray==2024.2.0
154
- xlrd==2.0.1
155
- ```
156
-
@@ -88,45 +88,3 @@ print("world")
88
88
  with CodeInterpreter() as sandbox:
89
89
  sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print, on_result=(lambda result: print(result.text)))
90
90
  ```
91
-
92
- ### Pre-installed Python packages inside the sandbox
93
-
94
- The full and always up-to-date list can be found in the [`requirements.txt`](https://github.com/e2b-dev/E2B/blob/stateful-code-interpreter/sandboxes/code-interpreter-stateful/requirements.txt) file.
95
-
96
- ```text
97
- # Jupyter server requirements
98
- jupyter-server==2.13.0
99
- ipykernel==6.29.3
100
- ipython==8.22.2
101
-
102
- # Other packages
103
- aiohttp==3.9.3
104
- beautifulsoup4==4.12.3
105
- bokeh==3.3.4
106
- gensim==4.3.2
107
- imageio==2.34.0
108
- joblib==1.3.2
109
- librosa==0.10.1
110
- matplotlib==3.8.3
111
- nltk==3.8.1
112
- numpy==1.26.4
113
- opencv-python==4.9.0.80
114
- openpyxl==3.1.2
115
- pandas==1.5.3
116
- plotly==5.19.0
117
- pytest==8.1.0
118
- python-docx==1.1.0
119
- pytz==2024.1
120
- requests==2.26.0
121
- scikit-image==0.22.0
122
- scikit-learn==1.4.1.post1
123
- scipy==1.12.0
124
- seaborn==0.13.2
125
- soundfile==0.12.1
126
- spacy==3.7.4
127
- textblob==0.18.0
128
- tornado==6.4
129
- urllib3==1.26.7
130
- xarray==2024.2.0
131
- xlrd==2.0.1
132
- ```
@@ -0,0 +1,4 @@
1
+ from e2b import *
2
+
3
+ from .main import CodeInterpreter, JupyterExtension
4
+ from .models import Execution, Error, Result, KernelException, MIMEType, Logs
@@ -2,10 +2,11 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
  import threading
5
+ import requests
6
+
5
7
  from concurrent.futures import Future
6
8
  from typing import Any, Callable, List, Optional, Dict
7
9
 
8
- import requests
9
10
  from e2b import EnvVars, ProcessMessage, Sandbox
10
11
  from e2b.constants import TIMEOUT
11
12
 
@@ -38,14 +38,13 @@ class Result:
38
38
  The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
39
39
 
40
40
  The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
41
- as a string, and the result can contain multiple types of data. The text representation is always present, and
42
- the other representations are optional.
41
+ as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
42
+ for the actual result the representation is always present for the result, the other representations are always optional.
43
43
 
44
44
  The class also provides methods to display the data in a Jupyter notebook.
45
45
  """
46
46
 
47
- text: str
48
- "Text representation of the result. Always present."
47
+ text: Optional[str] = None
49
48
  html: Optional[str] = None
50
49
  markdown: Optional[str] = None
51
50
  svg: Optional[str] = None
@@ -68,7 +67,7 @@ class Result:
68
67
  self.is_main_result = is_main_result
69
68
  self.raw = copy.deepcopy(data)
70
69
 
71
- self.text = data.pop("text/plain")
70
+ self.text = data.pop("text/plain", None)
72
71
  self.html = data.pop("text/html", None)
73
72
  self.markdown = data.pop("text/markdown", None)
74
73
  self.svg = data.pop("image/svg+xml", None)
@@ -80,6 +79,12 @@ class Result:
80
79
  self.javascript = data.pop("application/javascript", None)
81
80
  self.extra = data
82
81
 
82
+ # Allows to iterate over formats()
83
+ def __getitem__(self, item):
84
+ if item in self.raw:
85
+ return self.raw[item]
86
+ return getattr(self, item)
87
+
83
88
  def formats(self) -> Iterable[str]:
84
89
  """
85
90
  Returns all available formats of the result.
@@ -111,7 +116,7 @@ class Result:
111
116
 
112
117
  return formats
113
118
 
114
- def __str__(self) -> str:
119
+ def __str__(self) -> Optional[str]:
115
120
  """
116
121
  Returns the text representation of the data.
117
122
 
@@ -119,7 +124,7 @@ class Result:
119
124
  """
120
125
  return self.text
121
126
 
122
- def _repr_html_(self) -> str:
127
+ def _repr_html_(self) -> Optional[str]:
123
128
  """
124
129
  Returns the HTML representation of the data.
125
130
 
@@ -127,7 +132,7 @@ class Result:
127
132
  """
128
133
  return self.html
129
134
 
130
- def _repr_markdown_(self) -> str:
135
+ def _repr_markdown_(self) -> Optional[str]:
131
136
  """
132
137
  Returns the Markdown representation of the data.
133
138
 
@@ -135,7 +140,7 @@ class Result:
135
140
  """
136
141
  return self.markdown
137
142
 
138
- def _repr_svg_(self) -> str:
143
+ def _repr_svg_(self) -> Optional[str]:
139
144
  """
140
145
  Returns the SVG representation of the data.
141
146
 
@@ -143,7 +148,7 @@ class Result:
143
148
  """
144
149
  return self.svg
145
150
 
146
- def _repr_png_(self) -> str:
151
+ def _repr_png_(self) -> Optional[str]:
147
152
  """
148
153
  Returns the base64 representation of the PNG data.
149
154
 
@@ -151,7 +156,7 @@ class Result:
151
156
  """
152
157
  return self.png
153
158
 
154
- def _repr_jpeg_(self) -> str:
159
+ def _repr_jpeg_(self) -> Optional[str]:
155
160
  """
156
161
  Returns the base64 representation of the JPEG data.
157
162
 
@@ -159,7 +164,7 @@ class Result:
159
164
  """
160
165
  return self.jpeg
161
166
 
162
- def _repr_pdf_(self) -> str:
167
+ def _repr_pdf_(self) -> Optional[str]:
163
168
  """
164
169
  Returns the PDF representation of the data.
165
170
 
@@ -167,7 +172,7 @@ class Result:
167
172
  """
168
173
  return self.pdf
169
174
 
170
- def _repr_latex_(self) -> str:
175
+ def _repr_latex_(self) -> Optional[str]:
171
176
  """
172
177
  Returns the LaTeX representation of the data.
173
178
 
@@ -175,7 +180,7 @@ class Result:
175
180
  """
176
181
  return self.latex
177
182
 
178
- def _repr_json_(self) -> dict:
183
+ def _repr_json_(self) -> Optional[dict]:
179
184
  """
180
185
  Returns the JSON representation of the data.
181
186
 
@@ -183,7 +188,7 @@ class Result:
183
188
  """
184
189
  return self.json
185
190
 
186
- def _repr_javascript_(self) -> str:
191
+ def _repr_javascript_(self) -> Optional[str]:
187
192
  """
188
193
  Returns the JavaScript representation of the data.
189
194
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "e2b-code-interpreter"
3
- version = "0.0.2"
3
+ version = "0.0.4"
4
4
  description = "E2B Code Interpreter - Stateful code execution"
5
5
  authors = ["e2b <hello@e2b.dev>"]
6
6
  license = "Apache-2.0"
@@ -12,9 +12,9 @@ packages = [{ include = "e2b_code_interpreter" }]
12
12
  [tool.poetry.dependencies]
13
13
  python = "^3.8"
14
14
 
15
- e2b = ">=0.14.11"
16
15
  pydantic = ">1, <3"
17
16
  websocket-client = "^1.7.0"
17
+ e2b = ">=0.17.0"
18
18
 
19
19
  [tool.poetry.group.dev.dependencies]
20
20
  black = "^24.3.0"
@@ -22,7 +22,6 @@ pytest = "^7.4.0"
22
22
  python-dotenv = "^1.0.0"
23
23
  pytest-dotenv = "^0.5.2"
24
24
 
25
-
26
25
  [build-system]
27
26
  requires = ["poetry-core"]
28
27
  build-backend = "poetry.core.masonry.api"
@@ -1,2 +0,0 @@
1
- from .main import CodeInterpreter, JupyterExtension
2
- from .models import Execution, Error, Result, KernelException