Skip to navigation

Code Execution

Execute code in your Scrapybara instance
1

Start an instance

from scrapybara import Scrapybara
client = Scrapybara(api_key="your_api_key")
instance = client.start_ubuntu()
2

Execute code directly

result = instance.code.execute(
code="print('Hello from Scrapybara!')",
kernel_name="python3" # Optional: specify kernel
)
3

List available kernels

kernels = instance.notebook.list_kernels()
4

Create a notebook

notebook = instance.notebook.create(
name="my_notebook",
kernel_name="python3"
)
5

Add and execute cells

# Add a code cell
cell = instance.notebook.add_cell(
notebook_id=notebook.id,
type="code",
content="print('Hello from Scrapybara!')"
)
# Execute the cell
result = instance.notebook.execute_cell(
notebook_id=notebook.id,
cell_id=cell.id
)
6

Execute entire notebook

# Execute all cells in the notebook
results = instance.notebook.execute(notebook_id=notebook.id)
7

Clean up

# Delete the notebook when done
instance.notebook.delete(notebook_id=notebook.id)