Skip to content

Commit d61d41b

Browse files
authored
Update README.md
1 parent 4e15ec3 commit d61d41b

File tree

1 file changed

+31
-102
lines changed

1 file changed

+31
-102
lines changed

python/README.md

Lines changed: 31 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,56 @@
11
<p align="center">
2-
<img width="100" src="/readme-assets/logo-circle.png" alt="e2b logo">
2+
<img width="100" src="https://raw.githubusercontent.com/e2b-dev/E2B/refs/heads/main/readme-assets/logo-circle.png" alt="e2b logo">
33
</p>
44

5-
6-
<h1 align="center">
7-
Code interpreter extension for Python
8-
</h1>
9-
105
<h4 align="center">
116
<a href="https://pypi.org/project/e2b/">
127
<img alt="Last 1 month downloads for the Python SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
138
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/pypi/dm/e2b?label=PyPI%20Downloads">
14-
</a>
15-
<a href="https://www.npmjs.com/package/e2b">
16-
<img alt="Last 1 month downloads for the Python SDK" loading="lazy" width="200" height="20" decoding="async" data-nimg="1"
17-
style="color:transparent;width:auto;height:100%" src="https://img.shields.io/npm/dm/e2b?label=NPM%20Downloads">
18-
</a>
9+
</a>
1910
</h4>
2011

21-
The repository contains a template and modules for the code interpreter sandbox. It is based on the Jupyter server and implements the Jupyter Kernel messaging protocol. This allows for sharing context between code executions and improves support for plotting charts and other display-able data.
12+
<!---
13+
<img width="100%" src="/readme-assets/preview.png" alt="Cover image">
14+
--->
15+
## What is E2B?
16+
[E2B](https://www.e2b.dev/) is an open-source infrastructure that allows you run to AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our [JavaScript SDK](https://www.npmjs.com/package/@e2b/code-interpreter) or [Python SDK](https://pypi.org/project/e2b_code_interpreter).
2217

23-
## Key Features
18+
## Run your first Sandbox
2419

25-
- **Stateful Execution**: Unlike traditional sandboxes that treat each code execution independently, this package maintains context across executions.
26-
- **Displaying Charts & Data**: Implements parts of the [Jupyter Kernel messaging protocol](https://jupyter-client.readthedocs.io/en/latest/messaging.html), which support for interactive features like plotting charts, rendering DataFrames, etc.
20+
### 1. Install SDK
2721

28-
## Installation
29-
30-
```sh
31-
pip install e2b-code-interpreter
22+
JavaScript / TypeScript
3223
```
33-
34-
## Examples
35-
36-
### Minimal example with the sharing context
37-
38-
```python
39-
from e2b_code_interpreter import Sandbox
40-
41-
with Sandbox() as sandbox:
42-
sandbox.run_code()("x = 1")
43-
44-
execution = sandbox.run_code()("x+=1; x")
45-
print(execution.text) # outputs 2
24+
npm i @e2b/code-interpreter
4625
```
4726

48-
### Get charts and any display-able data
49-
50-
```python
51-
import base64
52-
import io
53-
54-
from matplotlib import image as mpimg, pyplot as plt
55-
56-
from e2b_code_interpreter import Sandbox
57-
58-
code = """
59-
import matplotlib.pyplot as plt
60-
import numpy as np
61-
62-
x = np.linspace(0, 20, 100)
63-
y = np.sin(x)
64-
65-
plt.plot(x, y)
66-
plt.show()
67-
"""
68-
69-
with Sandbox() as sandbox:
70-
# you can install dependencies in "jupyter notebook style"
71-
sandbox.run_code("!pip install matplotlib")
72-
73-
# plot random chart
74-
execution = sandbox.run_code(code)
75-
76-
# there's your image
77-
image = execution.results[0].png
78-
79-
# example how to show the image / prove it works
80-
i = base64.b64decode(image)
81-
i = io.BytesIO(i)
82-
i = mpimg.imread(i, format='PNG')
27+
Python
28+
```
29+
pip install e2b-code-interpreter
30+
```
8331

84-
plt.imshow(i, interpolation='nearest')
85-
plt.show()
32+
### 2. Get your E2B API key
33+
1. Sign up to E2B [here](https://e2b.dev).
34+
2. Get your API key [here](https://e2b.dev/dashboard?tab=keys).
35+
3. Set environment variable with your API key.
8636
```
37+
E2B_API_KEY=e2b_***
38+
```
8739

88-
### Streaming code output
40+
### 3. Execute code with code interpreter inside Sandbox
8941

90-
```python
42+
Python
43+
```py
9144
from e2b_code_interpreter import Sandbox
9245

93-
code = """
94-
import time
95-
import pandas as pd
96-
97-
print("hello")
98-
time.sleep(3)
99-
data = pd.DataFrame(data=[[1, 2], [3, 4]], columns=["A", "B"])
100-
display(data.head(10))
101-
time.sleep(3)
102-
print("world")
103-
"""
104-
10546
with Sandbox() as sandbox:
106-
sandbox.run_code(code, on_stdout=print, on_stderr=print, on_result=(lambda result: print(result.text)))
47+
sandbox.run_code("x = 1")
48+
execution = sandbox.run_code("x+=1; x")
49+
print(execution.text) # outputs 2
10750
```
10851

109-
### More resources
110-
- Check out the [JavaScript/TypeScript](https://e2b.dev/docs/hello-world/js) and [Python](https://e2b.dev/docs/hello-world/py) "Hello World" guides to learn how to use our SDK.
111-
112-
- See [E2B documentation](https://e2b.dev/docs) to get started.
113-
114-
- Visit our [Cookbook](https://github.com/e2b-dev/e2b-cookbook/tree/main) to get inspired by examples with different LLMs and AI frameworks.
115-
116-
___
52+
### 4. Check docs
53+
Visit [E2B documentation](https://e2b.dev/docs).
11754

118-
<div align='center'>
119-
<!-- <a href="https://e2b.dev/docs" target="_blank">
120-
<img src="https://img.shields.io/badge/docs-%2300acee.svg?color=143D52&style=for-the-badge&logo=x&logoColor=white" alt=docs style="margin-bottom: 5px;"/></a> -->
121-
<a href="https://twitter.com/e2b_dev" target="_blank">
122-
<img src="https://img.shields.io/badge/x (twitter)-%2300acee.svg?color=000000&style=for-the-badge&logo=x&logoColor=white" alt=linkedin style="margin-bottom: 5px;"/></a>
123-
<a href="https://discord.com/invite/U7KEcGErtQ" target="_blank">
124-
<img src="https://img.shields.io/badge/discord -%2300acee.svg?color=143D52&style=for-the-badge&logo=discord&logoColor=white" alt=discord style="margin-bottom: 5px;"/></a>
125-
<a href="https://www.linkedin.com/company/e2b-dev/" target="_blank">
126-
<img src="https://img.shields.io/badge/linkedin-%2300acee.svg?color=000000&style=for-the-badge&logo=linkedin&logoColor=white" alt=linkedin style="margin-bottom: 5px;"/></a>
127-
</div align='center'>
55+
### 5. E2B cookbook
56+
Visit our [Cookbook](https://github.com/e2b-dev/e2b-cookbook/tree/main) to get inspired by examples with different LLMs and AI frameworks.

0 commit comments

Comments
 (0)