Code Execution

Execute code in your Scrapybara instance

1

Start an instance

1from scrapybara import Scrapybara
2
3client = Scrapybara(api_key="your_api_key")
4instance = client.start(instance_type="small")
2

Execute code directly

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

List available kernels

1kernels = instance.notebook.list_kernels()
4

Create a notebook

1notebook = instance.notebook.create(
2 name="my_notebook",
3 kernel_name="python3"
4)
5

Add and execute cells

1# Add a code cell
2cell = instance.notebook.add_cell(
3 notebook_id=notebook.id,
4 type="code",
5 content="print('Hello from Scrapybara!')"
6)
7
8# Execute the cell
9result = instance.notebook.execute_cell(
10 notebook_id=notebook.id,
11 cell_id=cell.id
12)
6

Execute entire notebook

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

Clean up

1# Delete the notebook when done
2instance.notebook.delete(notebook_id=notebook.id)
Built with