Using the CoCalc API to run code using any of our supported Jupyter kernels
You can use a CoCalc API key to evaluate code using any of our supported kernels. Get your API key in account config.
Context: For more about CoCalc's API, see https://doc.cocalc.com/api and https://doc.cocalc.com/api2.
The Global Jupyter API Sandbox
https://cocalc.com has a pool of sandboxed projects that are always running and available for you to evaluate code via the API.
Available kernels
Get the available kernels at the https://cocalc.com/api/v2/jupyter/kernels endpoint.
Result:
Evaluate code
You can call any of the named kernels as follows:
Result:
When you use a kernel, a pool of pre-started kernels is also warmed up in sandboxed project so that future calls are quick.
Here's an example using SageMath:
Result:
You can also pass in history and then use it in the input:
Result:
In Your Own Projects
You can also evaluate code using any Jupyter kernel in any of your own projects. Note that this is potentially dangerous, since running code can delete or access any data in that project. When you use a kernel, a pool of pre-started kernels is also warmed up in your project so that future calls are quick, until the pool turns off.
The API is exactly the same as above, except you also pass in the project_id
, and optionally a path
where the code should run. That's it.