Skip to content

Code interpreter

Run code in stateful kernels and read results, logs, errors and charts.

Every method shows the same operation in each SDK; pick a language once and every tab on the site follows it.

Python TypeScript Go Ruby Java

What running a cell produced.

Property Type Description
error Optional[ExecutionError]
execution_count Optional[int]
logs Logs
results List[Result]
truncated bool

Not in the Python SDK’s Execution.

Not in the Python SDK’s Execution.

text: Optional[str]

Property (read-only).

The text of the cell’s value, the main result, if it has one.

Not in the Python SDK’s Execution.

Python TypeScript Go Ruby Java

One output of a cell: its value or something it displayed, in every representation the kernel gave.

Property Type Description
chart Optional[Chart]
data Optional[dict]
extra Optional[dict]
html Optional[str]
is_main_result bool
javascript Optional[str]
jpeg Optional[str]
json Optional[Any]
latex Optional[str]
markdown Optional[str]
pdf Optional[str]
png Optional[str]
svg Optional[str]
text Optional[str]

Not in the Python SDK’s Result.

Not in the Python SDK’s Result.

def formats(self) -> List[str]

Returns List[str]

Source: sdk/python/svm/code_interpreter_models.py:76
def from_mime_map(cls, outputs: Dict[str, str], *, main: bool) -> 'Result'
static
Parameter Type Default
outputs Dict[str, str]
main bool

Returns 'Result'

Source: sdk/python/svm/code_interpreter_models.py:83

Not in the Python SDK’s Result.

Python TypeScript Go Ruby Java

Everything a cell printed.

Property Type Description
stderr List[str]
stdout List[str]

Not in the Python SDK’s Logs.

Python TypeScript Go Ruby Java

One line of stdout or stderr from a cell.

Property Type Description
error bool
line str
timestamp int

Not in the Python SDK’s OutputMessage.

Python TypeScript Go Ruby Java

A running kernel, which keeps its variables between cells.

Property Type Description
cwd str
id str
language str

Not in the Python SDK’s Context.

Python TypeScript Go Ruby Java

The error a cell ended with.

Property Type Description
name str
traceback str
value str

Not in the Python SDK’s ExecutionError.

Not in the Python SDK’s ExecutionError.

Python TypeScript Go Ruby Java

The interpreter could not run the request (bad arguments, no kernel in the image, a timeout).

Python exposes these as methods; see below.

Not in the Python SDK’s CodeInterpreterError.

Python TypeScript Go Ruby Java

A cell did not finish within its timeout.

Not in the Python SDK’s ExecutionTimeoutError.

Not in the Python SDK’s ExecutionTimeoutError.

Python TypeScript Go Ruby Java

A chart: type, title and its elements (what they are depends on the type).

Property Type Description
elements List[Any]
title Optional[str]
type ChartType

Not in the Python SDK’s Chart.

Not in the Python SDK’s Chart.

Not in the Python SDK’s Chart.

Python TypeScript Go Ruby Java
Property Type Description
elements List[Any]
title Optional[str]
type ChartType
x_label Optional[str]
x_unit Optional[str]
y_label Optional[str]
y_unit Optional[str]
Python TypeScript Go Ruby Java

Typed charts from a cell’s matplotlib figures (G25): Result.chart, read from the kernel’s application/vnd.svm.chart+json output.

The shape follows the reference vendor’s charts (field names as on the wire): Chart (type, title, elements), 2D charts add axis labels and units, point charts (LineChart, ScatterChart) add ticks and scales, and SuperChart holds one chart per axes of a figure with several. deserializeChart builds the right object from the JSON; a type it does not know is a plain chart of type unknown.

Python TypeScript Go Ruby Java

ScaleType is an axis scale; “linear” when the kernel names none this SDK knows.

Python TypeScript Go Ruby Java

LineChart and ScatterChart are point charts of their type.

Property Type Description
elements List[PointData]
title Optional[str]
type ChartType
x_label Optional[str]
x_scale ScaleType
x_tick_labels List[str]
x_ticks List[Coordinate]
x_unit Optional[str]
y_label Optional[str]
y_scale ScaleType
y_tick_labels List[str]
y_ticks List[Coordinate]
y_unit Optional[str]

Not in the Python SDK’s LineChart.

Python TypeScript Go Ruby Java

LineChart and ScatterChart are point charts of their type.

Property Type Description
elements List[PointData]
title Optional[str]
type ChartType
x_label Optional[str]
x_scale ScaleType
x_tick_labels List[str]
x_ticks List[Coordinate]
x_unit Optional[str]
y_label Optional[str]
y_scale ScaleType
y_tick_labels List[str]
y_ticks List[Coordinate]
y_unit Optional[str]

Not in the Python SDK’s ScatterChart.

Python TypeScript Go Ruby Java

PointChart is what LineChart and ScatterChart share.

Property Type Description
elements List[PointData]
title Optional[str]
type ChartType
x_label Optional[str]
x_scale ScaleType
x_tick_labels List[str]
x_ticks List[Coordinate]
x_unit Optional[str]
y_label Optional[str]
y_scale ScaleType
y_tick_labels List[str]
y_ticks List[Coordinate]
y_unit Optional[str]
Python TypeScript Go Ruby Java

One series: its label and points as (x, y); a coordinate is a number, an ISO time on a datetime axis or a name on a categorical one.

Property Type Description
label str
points List[Tuple[Coordinate, Coordinate]]
Python TypeScript Go Ruby Java

BarChart is a bar chart.

Property Type Description
elements List[BarData]
title Optional[str]
type ChartType
x_label Optional[str]
x_unit Optional[str]
y_label Optional[str]
y_unit Optional[str]

Not in the Python SDK’s BarChart.

Python TypeScript Go Ruby Java

BarData is one bar: its label, group and value (text, as the reference vendor has it).

Property Type Description
group str
label str
value str
Python TypeScript Go Ruby Java

PieChart is a pie chart.

Property Type Description
elements List[PieData]
title Optional[str]
type ChartType

Not in the Python SDK’s PieChart.

Python TypeScript Go Ruby Java

PieData is one wedge.

Property Type Description
angle float
label str
radius float
Python TypeScript Go Ruby Java

BoxAndWhiskerChart is a box-and-whisker chart.

Property Type Description
elements List[BoxAndWhiskerData]
title Optional[str]
type ChartType
x_label Optional[str]
x_unit Optional[str]
y_label Optional[str]
y_unit Optional[str]

Not in the Python SDK’s BoxAndWhiskerChart.

Python TypeScript Go Ruby Java

BoxAndWhiskerData is one box.

Property Type Description
first_quartile float
label str
max float
median float
min float
outliers List[float]
third_quartile float
Python TypeScript Go Ruby Java

SuperChart holds one chart per axes of a figure with several.

Property Type Description
elements List[Chart]
title Optional[str]
type ChartType

Not in the Python SDK’s SuperChart.