
Details

- ExternalObject is a reference to external data that is returned by some ExternalEvaluate systems, such as "Python", "Ruby", "NodeJS".
- An ExternalObject[…] is specific to a particular ExternalSessionObject, which may not be persistent.
- ExternalObject[…]["name"] in most evaluators is identical to ExternalObject[…][ExternalOperation["GetAttribute", "name"]].
- ExternalObject[…][ExternalOperation[…]] is equivalent to ExternalEvaluate[session,ExternalOperation[…][ExternalObject[…]]], where session is implied by the ExternalObject[…].
- ExternalObject[…][op1,op2,…] is identical to ExternalEvaluate[session,RightComposition[op1,op2,…][ExternalObject[…]]].
- ExternalObject[…][{op1,op2,…}] is identical to ExternalEvaluate[session, {op1[ExternalObject[…]],op2[ExternalObject[…]],…}].
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (7)Survey of the scope of standard use cases
The keys displayed for functions in Python differ between a built-in function and a user-defined function:

https://wolfram.com/xid/0eny092r2-mgqemg

Define an object in Python and display it:

https://wolfram.com/xid/0eny092r2-8x7mug


https://wolfram.com/xid/0eny092r2-izrruj
External Operations (6)
"Eval" (2)
Start a Python session to work with strings:

https://wolfram.com/xid/0eny092r2-jjm2rl

Create an ExternalObject with a string that contains valid Python code:

https://wolfram.com/xid/0eny092r2-swuxd6

Use the "Eval" operation to evaluate the string to Python code:

https://wolfram.com/xid/0eny092r2-uu8arf


https://wolfram.com/xid/0eny092r2-tzoug5
Start a Python session to work with strings:

https://wolfram.com/xid/0eny092r2-x4l9wv

Create an ExternalObject with a string that contains valid Python code with variables:

https://wolfram.com/xid/0eny092r2-e06xod

Use the "Eval" operation to evaluate the string to Python code, using an evaluation context:

https://wolfram.com/xid/0eny092r2-829z99


https://wolfram.com/xid/0eny092r2-0yq2q
"Call" (1)

https://wolfram.com/xid/0eny092r2-4219i

Define an ExternalObject that creates a function in Python:

https://wolfram.com/xid/0eny092r2-9h6w6f

Call the function by running the ExternalOperation "Call":

https://wolfram.com/xid/0eny092r2-thi0xa

Any argument of the "Call" operation can be an ExternalOperation:

https://wolfram.com/xid/0eny092r2-bvf64x

ExternalObject can also be used as an argument:

https://wolfram.com/xid/0eny092r2-zq8db7


https://wolfram.com/xid/0eny092r2-s7pq8q

Arguments can also be passed directly in ExternalEvaluate by doing:

https://wolfram.com/xid/0eny092r2-7rmkso

The result is equivalent to running the following Python code:

https://wolfram.com/xid/0eny092r2-knfcqv


https://wolfram.com/xid/0eny092r2-qkk4vh
"GetAttribute" (1)
Start a Python session to work with dates:

https://wolfram.com/xid/0eny092r2-d7wsz4
Return an ExternalObject for a datetime object:

https://wolfram.com/xid/0eny092r2-zkk45a

Extract the year attribute by using "GetAttribute":

https://wolfram.com/xid/0eny092r2-jfln28

The same can be done using an ExternalObject subvalue:

https://wolfram.com/xid/0eny092r2-1rthe2

For the Python evaluator, "GetAttribute" is the default operation, and ExternalOperation can be omitted:

https://wolfram.com/xid/0eny092r2-cotv78

The result is equivalent to running the following Python code:

https://wolfram.com/xid/0eny092r2-b1282w


https://wolfram.com/xid/0eny092r2-u5uste
"SetAttribute" (1)
Start a Python session to work with decimal numbers:

https://wolfram.com/xid/0eny092r2-lf5zl4
Get the context for the decimal module:

https://wolfram.com/xid/0eny092r2-ds819o


https://wolfram.com/xid/0eny092r2-602p3t
Check that the precision was set to 6:

https://wolfram.com/xid/0eny092r2-4c6pmi


https://wolfram.com/xid/0eny092r2-cbzrou

The result is equivalent to running the following Python code:

https://wolfram.com/xid/0eny092r2-by53sd

https://wolfram.com/xid/0eny092r2-c3tha6
"Cast" (1)
Create an ExternalObject that represents the current date:

https://wolfram.com/xid/0eny092r2-2ful7n

https://wolfram.com/xid/0eny092r2-lh03sx

Use "Expression" to return the object as a Wolfram Language expression:

https://wolfram.com/xid/0eny092r2-k0ehns

The Cast operation can also run in ExternalObject subvalues:

https://wolfram.com/xid/0eny092r2-jeanm1

The symbol Expression is a shortcut for the same:

https://wolfram.com/xid/0eny092r2-pdqz05

Return the object as a string:

https://wolfram.com/xid/0eny092r2-gqmk1m

The symbol String is a shortcut for the same:

https://wolfram.com/xid/0eny092r2-yg8hmp

Return the object as an ExternalObject:

https://wolfram.com/xid/0eny092r2-yt1eew

The symbol ExternalObject is a shortcut for the same:

https://wolfram.com/xid/0eny092r2-xiafcd

The same can be achieved by using "ReturnType" in ExternalEvaluate:

https://wolfram.com/xid/0eny092r2-bnmhjm


https://wolfram.com/xid/0eny092r2-wdx7xb
Properties & Relations (6)Properties of the function, and connections to other functions
ExternalOperation can be used to extract the operation from an ExternalObject:

https://wolfram.com/xid/0eny092r2-p7tziq

The same can be done with an ExternalFunction:

https://wolfram.com/xid/0eny092r2-dif7v0

ExternalOperation can be used as an argument to ExternalObject:

https://wolfram.com/xid/0eny092r2-ixfzu5

The executed operation is identical to the following one:

https://wolfram.com/xid/0eny092r2-mu3hbe

Which can be executed with ExternalEvaluate:

https://wolfram.com/xid/0eny092r2-7b07hd

The result is equivalent to running the following Python code:

https://wolfram.com/xid/0eny092r2-pzgu6c

Create an ExternalObject to work with the sys module:

https://wolfram.com/xid/0eny092r2-tp546g

When a string is used, the "GetAttribute" operation is executed in most evaluators, including Python:

https://wolfram.com/xid/0eny092r2-egqaxa

The result is equivalent to running an explicit "GetAttribute" operation:

https://wolfram.com/xid/0eny092r2-9dppjt


https://wolfram.com/xid/0eny092r2-k1043h

Create an ExternalObject:

https://wolfram.com/xid/0eny092r2-3de5c9

Use ExternalFunction to run methods on the object:

https://wolfram.com/xid/0eny092r2-nsaukm


https://wolfram.com/xid/0eny092r2-vb2q92

https://wolfram.com/xid/0eny092r2-bsyuoc

Create an ExternalObject for the datetime module:

https://wolfram.com/xid/0eny092r2-zsnlru

Create an ExternalObject with the current date and another one with a timedelta:

https://wolfram.com/xid/0eny092r2-s542nf

Send back the objects using an ExternalFunction:

https://wolfram.com/xid/0eny092r2-cwcyon

The same can be done with an ExternalEvaluate call:

https://wolfram.com/xid/0eny092r2-i9xnki

Use "ReturnType" to return a String:

https://wolfram.com/xid/0eny092r2-3r3rxu


https://wolfram.com/xid/0eny092r2-in0ms8
Multiple operations can be concatenated using multiple arguments in ExternalObject:

https://wolfram.com/xid/0eny092r2-o4lbb2


https://wolfram.com/xid/0eny092r2-oxalvx

Which can be written in a more compact way:

https://wolfram.com/xid/0eny092r2-ey2dbb

Possible Issues (1)Common pitfalls and unexpected behavior
Running successive operations using downvalues can lead to undefined behavior without checking the return value at every step:

https://wolfram.com/xid/0eny092r2-4gjf7v

https://wolfram.com/xid/0eny092r2-j4knlk


https://wolfram.com/xid/0eny092r2-7s5qxn

This is happening because the first operation is returning an ExternalFunction (since date is a class that can be initialized) and you are passing an incomplete ExternalOperation to the date constructor:

https://wolfram.com/xid/0eny092r2-38hbg1

In order to safely chain operations without checking the return type at every step, run all operations at once:

https://wolfram.com/xid/0eny092r2-rh80cu

A Failure object is returned as soon as any operation fails, preventing others from running:

https://wolfram.com/xid/0eny092r2-zxk03r


https://wolfram.com/xid/0eny092r2-1u6vqw
Neat Examples (1)Surprising or curious use cases
Start a Python session to play chess:

https://wolfram.com/xid/0eny092r2-69y4m0

Create an ExternalObject to represent that state of the chess board:

https://wolfram.com/xid/0eny092r2-5qubie

Define a function to plot the board:

https://wolfram.com/xid/0eny092r2-lbo6yx
Use the function to plot the board:

https://wolfram.com/xid/0eny092r2-yywky5

Extract the current move number by extracting an attribute from the object:

https://wolfram.com/xid/0eny092r2-5snecj

Move a piece by running a function; it will change the state of the external object:

https://wolfram.com/xid/0eny092r2-vf6glr

Plot the board again to display the new configuration:

https://wolfram.com/xid/0eny092r2-xuhsa5

You can now compute all legal moves that can be done with the current configuration:

https://wolfram.com/xid/0eny092r2-xnoclv
Create a method caller for the "UCI" property by chaining external operations:

https://wolfram.com/xid/0eny092r2-dsdo7o

Compute the UCI string for one move:

https://wolfram.com/xid/0eny092r2-oymcf9

You can now execute one random move:

https://wolfram.com/xid/0eny092r2-lmxasj

You can use the plot function to show the board again:

https://wolfram.com/xid/0eny092r2-yv9hcj

Create a function to play random moves:

https://wolfram.com/xid/0eny092r2-qmr9xi

https://wolfram.com/xid/0eny092r2-m6gati

Show the current move counter:

https://wolfram.com/xid/0eny092r2-f4bygb


https://wolfram.com/xid/0eny092r2-wiubbv
Wolfram Research (2018), ExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalObject.html (updated 2024).
Text
Wolfram Research (2018), ExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalObject.html (updated 2024).
Wolfram Research (2018), ExternalObject, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalObject.html (updated 2024).
CMS
Wolfram Language. 2018. "ExternalObject." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/ExternalObject.html.
Wolfram Language. 2018. "ExternalObject." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/ExternalObject.html.
APA
Wolfram Language. (2018). ExternalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalObject.html
Wolfram Language. (2018). ExternalObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalObject.html
BibTeX
@misc{reference.wolfram_2025_externalobject, author="Wolfram Research", title="{ExternalObject}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ExternalObject.html}", note=[Accessed: 25-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_externalobject, organization={Wolfram Research}, title={ExternalObject}, year={2024}, url={https://reference.wolfram.com/language/ref/ExternalObject.html}, note=[Accessed: 25-March-2025
]}