How to | Create Embeddable Code

You can generate code for external environments or other languages in the Wolfram Language by using EmbedCode. Note: Evaluation of cloud objects will use some of your Wolfram Cloud Credits.

This uses EmbedCode with CloudDeploy to generate a string that can be inserted into the HTML of a web page:

Click for copyable input

Adding this code to an HTML document and viewing it will give a form for filling in the parameters "x" and "y":


EmbedCode can also generate code for other languages.

This generates a full Python file that can be pasted into a Python script:

Click for copyable input

Start Python in a terminal, paste the code from EmbedCode, and apply call:

$ python
Python 2.7.5 (default, Dec 7 2013, 22:34:15)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlencode
>>> from urllib2 import urlopen
>>> def wolfram_cloud _call(**args):
... arguments = dict([(key, arg) for key, arg in args.iteritems()])
... result = urlopen("", urlencode(arguments))
... return
>>> def call(x):
... return wolfram_cloud_call(x=x)
>>> call(2)
>>> call(5)
>>> call(10)

This uses EmbedCode generates a full Java file that can be pasted into a Java project:

Click for copyable input

For strongly typed languages like Java, you need to add the option ExternalTypeSignature. ExternalTypeSignature is a list of two things: argument types and return types. The argument types parameter can often be deduced automatically, but you will need to specify the return type parameter. In the case of the EmbedCode above, it is "double". Set Automatic to use the default behavior for the argument types. These values are strings in the native type names of the destination language.

Here is what a simple project might look like in Eclipse:

See Also

EmbedCode  APIFunction  CloudDeploy