2929
3030
3131class  JupyterExtension :
32+     """ 
33+     Code interpreter module for executing code in a stateful context. 
34+     """ 
35+ 
3236    _exec_timeout  =  300 
3337
3438    @property  
@@ -56,6 +60,20 @@ async def exec_cell(
5660        timeout : Optional [float ] =  None ,
5761        request_timeout : Optional [float ] =  None ,
5862    ) ->  Execution :
63+         """ 
64+         Runs the code in the specified context, if not specified, the default context is used. 
65+         You can reference previously defined variables, imports, and functions in the code. 
66+ 
67+         :param code: The code to execute 
68+         :param kernel_id: The context id 
69+         :param on_stdout: Callback for stdout messages 
70+         :param on_stderr: Callback for stderr messages 
71+         :param on_result: Callback for the `Result` object 
72+         :param envs: Environment variables 
73+         :param timeout: Max time to wait for the execution to finish 
74+         :param request_timeout: Max time to wait for the request to finish 
75+         :return: Execution object 
76+         """ 
5977        logger .debug (f"Executing code { code }  )
6078
6179        timeout  =  None  if  timeout  ==  0  else  (timeout  or  self ._exec_timeout )
@@ -98,9 +116,18 @@ async def create_kernel(
98116        self ,
99117        cwd : Optional [str ] =  None ,
100118        kernel_name : Optional [str ] =  None ,
101-         request_timeout : Optional [float ] =  None ,
102119        envs : Optional [Dict [str , str ]] =  None ,
120+         request_timeout : Optional [float ] =  None ,
103121    ) ->  str :
122+         """ 
123+         Creates a new context to run code in. 
124+ 
125+         :param cwd: Set the current working directory for the context 
126+         :param kernel_name: Type of the context 
127+         :param envs: Environment variables 
128+         :param request_timeout: Max time to wait for the request to finish 
129+         :return: Context id 
130+         """ 
104131        logger .debug (f"Creating new kernel { kernel_name }  )
105132
106133        data  =  {}
@@ -132,6 +159,12 @@ async def shutdown_kernel(
132159        kernel_id : Optional [str ] =  None ,
133160        request_timeout : Optional [float ] =  None ,
134161    ) ->  None :
162+         """ 
163+         Shuts down a context. 
164+ 
165+         :param kernel_id: Context id 
166+         :param request_timeout: Max time to wait for the request to finish 
167+         """ 
135168        kernel_id  =  kernel_id  or  DEFAULT_KERNEL_ID 
136169
137170        logger .debug (f"Shutting down a kernel with id { kernel_id }  )
@@ -153,6 +186,13 @@ async def restart_kernel(
153186        kernel_id : Optional [str ] =  None ,
154187        request_timeout : Optional [float ] =  None ,
155188    ) ->  None :
189+         """ 
190+         Restarts the context. 
191+         Restarting will clear all variables, imports, and other settings set during previous executions. 
192+ 
193+         :param kernel_id: Context id 
194+         :param request_timeout: Max time to wait for the request to finish 
195+         """ 
156196        kernel_id  =  kernel_id  or  DEFAULT_KERNEL_ID 
157197
158198        logger .debug (f"Restarting kernel { kernel_id }  )
@@ -173,6 +213,14 @@ async def list_kernels(
173213        self ,
174214        request_timeout : Optional [float ] =  None ,
175215    ) ->  List [Kernel ]:
216+         """ 
217+         Lists all available contexts. 
218+ 
219+         :param request_timeout: Max time to wait for the request to finish 
220+         :return: List of Kernel objects 
221+         """ 
222+         logger .debug ("Listing kernels" )
223+ 
176224        try :
177225            response  =  await  self ._client .get (
178226                f"{ self ._url }  ,
@@ -194,6 +242,9 @@ class AsyncCodeInterpreter(AsyncSandbox):
194242
195243    @property  
196244    def  notebook (self ) ->  JupyterExtension :
245+         """ 
246+         Code interpreter module for executing code in a stateful context. 
247+         """ 
197248        return  self ._notebook 
198249
199250    def  __init__ (self , sandbox_id : str , connection_config : ConnectionConfig ):
0 commit comments