SageMath is an open-source project to create mathematical software that is a free alternative to proprietary, closed-source packages. One way to access it on the Internet is through the SageMathcell server, where code can be entered and evaluated. It can also be accessed as a web service for situations requiring more interactive access to the data output.

The URL for accessing the web API is The secure URL is necessary to avoid CORS errors. Appending a trailing slash to this URL produces an additional CORS error when retrieving data. The code to be executed must be URL encoded as a URL component, not a full URL. The encoded string is then POSTed to the server with a prefix code= and a JSON response returned with the result of the interaction.

Here is some simple JavaScript code to send a request to the server:

var xhr = new XMLHttpRequest();

xhr.onload = function() {

  var data = JSON.parse( xhr.response );
  callback( data.stdout );

}; 'POST', '', true );
xhr.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded' );
xhr.send( 'code=' + encodeURIComponent( codeString ) );

The standard output is processed in the callback function.

Here is a simple interface for viewing the full JSON result returned by the server. Enter SageMath code in the input box and activate the button:

Output will go here

It appears to be necessary to include a print() statement in the code in order for a result to appear in the standard output. The server times out after thirty seconds, returning a success value of false.

If a URL-encoded query string is appended to the location of this page, it will be evaluated automatically as Python and the result will appear here:

Output will go here

Projects and presentations utilizing the SageMath web service:

Special Functions Explorer - SageMath

An interactive Three.js viewer for visualizing the real and imaginary parts of special functions in the complex plane. Includes most native SageMath functions of one variable and an index or modulus.

SageMath Online Integrator

A simple interface for evaluating indefinite integrals. To be compared with Wolfram’s legacy integrator.

Uploaded 2016.08.27 — Updated 2019.06.19