Skip to content

Commit d2fec4b

Browse files
committed
Update readmes
1 parent f31d7f1 commit d2fec4b

File tree

3 files changed

+63
-42
lines changed

3 files changed

+63
-42
lines changed

README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ from e2b_code_interpreter import CodeInterpreter
3939
with CodeInterpreter() as sandbox:
4040
sandbox.notebook.exec_cell("x = 1")
4141

42-
result = sandbox.notebook.exec_cell("x+=1; x")
43-
print(result.text) # outputs 2
42+
execution = sandbox.notebook.exec_cell("x+=1; x")
43+
print(execution.text) # outputs 2
4444

4545
```
4646

@@ -52,8 +52,8 @@ import { CodeInterpreter } from '@e2b/code-interpreter'
5252
const sandbox = await CodeInterpreter.create()
5353
await sandbox.notebook.execCell('x = 1')
5454

55-
const result = await sandbox.notebook.execCell('x+=1; x')
56-
console.log(result.text) // outputs 2
55+
const execution = await sandbox.notebook.execCell('x+=1; x')
56+
console.log(execution.text) // outputs 2
5757

5858
await sandbox.close()
5959
```
@@ -86,10 +86,10 @@ with CodeInterpreter() as sandbox:
8686
sandbox.notebook.exec_cell("!pip install matplotlib")
8787

8888
# plot random graph
89-
result = sandbox.notebook.exec_cell(code)
89+
execution = sandbox.notebook.exec_cell(code)
9090

9191
# there's your image
92-
image = result.results[0].png
92+
image = execution.results[0].png
9393

9494
# example how to show the image / prove it works
9595
i = base64.b64decode(image)
@@ -121,10 +121,10 @@ plt.show()
121121
// you can install dependencies in "jupyter notebook style"
122122
await sandbox.notebook.execCell("!pip install matplotlib")
123123

124-
const result = await sandbox.notebook.execCell(code)
124+
const execution = await sandbox.notebook.execCell(code)
125125

126126
// this contains the image data, you can e.g. save it to file or send to frontend
127-
result.data[0].png
127+
execution.results[0].png
128128

129129
await sandbox.close()
130130
```
@@ -138,36 +138,47 @@ from e2b_code_interpreter import CodeInterpreter
138138

139139
code = """
140140
import time
141+
import pandas as pd
141142
142143
print("hello")
143-
time.sleep(5)
144+
time.sleep(3)
145+
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
146+
display(data.head(10))
147+
time.sleep(3)
144148
print("world")
145149
"""
150+
146151
with CodeInterpreter() as sandbox:
147-
sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print)
152+
sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print, on_display_data=(lambda data: print(data.text)))
153+
148154
```
149155

150156
#### JavaScript
151157

152158
```js
153159
import { CodeInterpreter } from '@e2b/code-interpreter'
154160

155-
code = `
161+
const code = `
156162
import time
163+
import pandas as pd
157164
158165
print("hello")
159-
time.sleep(5)
166+
time.sleep(3)
167+
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
168+
display(data.head(10))
169+
time.sleep(3)
160170
print("world")
161171
`
162172

163173
const sandbox = await CodeInterpreter.create()
164174

165175
await sandbox.notebook.execCell(code, {
166176
onStdout: (out) => console.log(out),
167-
onStderr: (outErr) => console.error(outErr)
168-
onDisplayData: (outData) => console.log(data.text)
177+
onStderr: (outErr) => console.error(outErr),
178+
onDisplayData: (outData) => console.log(outData.text)
169179
})
170180

181+
await sandbox.close()
171182
```
172183

173184
### Pre-installed Python packages inside the sandbox

js/README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { CodeInterpreter } from '@e2b/code-interpreter'
2323
const sandbox = await CodeInterpreter.create()
2424
await sandbox.notebook.execCell('x = 1')
2525

26-
const result = await sandbox.notebook.execCell('x += 1; x')
27-
console.log(result.text) // outputs 2
26+
const execution = await sandbox.notebook.execCell('x+=1; x')
27+
console.log(execution.text) // outputs 2
2828

2929
await sandbox.close()
3030
```
@@ -45,15 +45,15 @@ y = np.sin(x)
4545
4646
plt.plot(x, y)
4747
plt.show()
48-
`
48+
`;
4949

5050
// you can install dependencies in "jupyter notebook style"
5151
await sandbox.notebook.execCell("!pip install matplotlib")
5252

53-
const result = await sandbox.notebook.execCell(code)
53+
const execution = await sandbox.notebook.execCell(code)
5454

5555
// this contains the image data, you can e.g. save it to file or send to frontend
56-
result.data[0].png
56+
execution.results[0].png
5757

5858
await sandbox.close()
5959
```
@@ -63,21 +63,27 @@ await sandbox.close()
6363
```js
6464
import { CodeInterpreter } from '@e2b/code-interpreter'
6565

66-
code = `
66+
const code = `
6767
import time
68+
import pandas as pd
6869
6970
print("hello")
70-
time.sleep(5)
71+
time.sleep(3)
72+
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
73+
display(data.head(10))
74+
time.sleep(3)
7175
print("world")
72-
`;
76+
`
7377

7478
const sandbox = await CodeInterpreter.create()
7579

76-
await sandbox.notebook.execCell(
77-
code,
78-
(out) => console.log(out),
79-
(outErr) => console.error(outErr),
80-
)
80+
await sandbox.notebook.execCell(code, {
81+
onStdout: (out) => console.log(out),
82+
onStderr: (outErr) => console.error(outErr),
83+
onDisplayData: (outData) => console.log(outData.text)
84+
})
85+
86+
await sandbox.close()
8187
```
8288

8389
### Pre-installed Python packages inside the sandbox

python/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pip install e2b-code-interpreter
2121
from e2b_code_interpreter import CodeInterpreter
2222

2323
with CodeInterpreter() as sandbox:
24-
sandbox.exec_cell("x = 1")
24+
sandbox.notebook.exec_cell("x = 1")
2525

26-
result = sandbox.exec_cell("x += 1; x")
27-
print(result.text) # outputs 2
26+
execution = sandbox.notebook.exec_cell("x+=1; x")
27+
print(execution.text) # outputs 2
2828

2929
```
3030

@@ -51,21 +51,21 @@ plt.show()
5151

5252
with CodeInterpreter() as sandbox:
5353
# you can install dependencies in "jupyter notebook style"
54-
sandbox.exec_cell("!pip install matplotlib")
54+
sandbox.notebook.exec_cell("!pip install matplotlib")
5555

5656
# plot random graph
57-
result = sandbox.exec_cell(code)
57+
execution = sandbox.notebook.exec_cell(code)
5858

59-
# there's your image
60-
image = result.display_data[0]["image/png"]
59+
# there's your image
60+
image = execution.results[0].png
6161

62-
# example how to show the image / prove it works
63-
i = base64.b64decode(image)
64-
i = io.BytesIO(i)
65-
i = mpimg.imread(i, format='PNG')
62+
# example how to show the image / prove it works
63+
i = base64.b64decode(image)
64+
i = io.BytesIO(i)
65+
i = mpimg.imread(i, format='PNG')
6666

67-
plt.imshow(i, interpolation='nearest')
68-
plt.show()
67+
plt.imshow(i, interpolation='nearest')
68+
plt.show()
6969
```
7070

7171
### Streaming code output
@@ -75,14 +75,18 @@ from e2b_code_interpreter import CodeInterpreter
7575

7676
code = """
7777
import time
78+
import pandas as pd
7879
7980
print("hello")
80-
time.sleep(5)
81+
time.sleep(3)
82+
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
83+
display(data.head(10))
84+
time.sleep(3)
8185
print("world")
8286
"""
8387

8488
with CodeInterpreter() as sandbox:
85-
sandbox.exec_cell(code, on_stdout=print, on_stderr=print)
89+
sandbox.notebook.exec_cell(code, on_stdout=print, on_stderr=print, on_display_data=(lambda data: print(data.text)))
8690
```
8791

8892
### Pre-installed Python packages inside the sandbox

0 commit comments

Comments
 (0)