StartExternalSession["sys"]
starts an external session using the external evaluator sys, returning an external session object.
StartExternalSession[assoc]
starts the external evaluator specified by assoc.
StartExternalSession[obj]
starts the external evaluator specified by ExternalEvaluatorObject.
StartExternalSession[{"sys",opts}]
uses the options opts for the external evaluator.
StartExternalSession[systype]
specifies that output from the external evaluator should be converted to the specified type.
StartExternalSession[DatabaseReference[ref]]
uses the database specified by ref to start a database session.
StartExternalSession["sys"]
starts an external session using the external evaluator sys, returning an external session object.
StartExternalSession[assoc]
starts the external evaluator specified by assoc.
StartExternalSession[obj]
starts the external evaluator specified by ExternalEvaluatorObject.
StartExternalSession[{"sys",opts}]
uses the options opts for the external evaluator.
StartExternalSession[systype]
specifies that output from the external evaluator should be converted to the specified type.
StartExternalSession[DatabaseReference[ref]]
uses the database specified by ref to start a database session.
Details
- StartExternalSession starts an external process that can be used to implement an external evaluator session in which there are multiple evaluations requested by ExternalEvaluate.
- In StartExternalSession[assoc], elements of the association can include:
-
"System" the external system or language to start "Evaluator" the specific evaluator to execute code "Name" the registered name of an evaluator "ID" a unique identifier "ReturnType" type of object to return ("String", "Expression", ...) "Prolog" code to run before the command "Epilog" code to run after the command "SessionProlog" code to run before the session "SessionEpilog" code to run after the session - "System" is the only required key; all others are optional.
- In StartExternalSession[sys], possible choices of sys include:
-
"Python" Python "NodeJS" JavaScript running through Node.js "Julia" Julia "Ruby" Ruby "R" R "Shell" Bash, Sh, Zsh, ... "Jupyter" Jupyter kernel "SQL" SQL database "SQL-JDBC" SQL database using JDBC - Possible settings for "type" in StartExternalSession[sys"type",…], or for "ReturnType", are dependent on the evaluation system, and typically include:
-
"Expression" attempt to convert to a Wolfram Language expression "String" give the raw string output by the external evaluator - The possible settings for evaluator in StartExternalSession[{sys,"Evaluator"evaluator},…] depend on sys, and include:
-
"path" path to a language executable DatabaseReference[…] an SQL database connection SQLConnection[…] an SQL-JDBC database connection - Typically, StartExternalSession uses the setting "ReturnType""Expression".
- StartExternalSession[{"sys",opts}] is equivalent to StartExternalSession[<|"System""sys",opts|>].
- StartExternalSession[{sys,"ID""id",…}] either returns an already running session with the given "id" or starts a new session with the unique "id".
- ExternalEvaluators gives a list of evaluator systems that can be used.
- ExternalSessions gives a list of active external sessions.
- DeleteObject[ExternalSessionObject[…]] kills and removes an external session started by StartExternalSession.
Examples
open all close allBasic Examples (2)
Start an external Python session, automatically discovering any usable installations:
session = StartExternalSession["Python"]ExternalEvaluate[session, "1+1"]Stop the session with DeleteObject:
DeleteObject[session]Start a new Python session in a provisioned environment:
session = StartExternalSession[
{
"Python",
"Evaluator" -> <|
"Dependencies" -> {"emoji"},
"EnvironmentName" -> "myenv",
"PythonRuntime" -> "3.11"
|>
}
]ExternalEvaluate[
session,
"import emoji; emoji.emojize('Emojis are :thumbs_up:')"
]Scope (16)
Basic Uses (2)
Multiple external sessions can be run simultaneously:
{StartExternalSession["Python"], StartExternalSession["NodeJS"], StartExternalSession["Julia"]}DeleteObject[%]Start an external Python session using the executable in /usr/bin/python3:
session = StartExternalSession[<|"System" -> "Python", "Evaluator" -> "/usr/bin/python3"|>]Use the session for multiple calls to ExternalEvaluate:
ExternalEvaluate[session, "x='hello world'"]ExternalEvaluate[session, "x"]Stop the session with DeleteObject:
DeleteObject[session]Session Options (14)
"ReturnType" (4)
For most systems, the default return type is "Expression":
session = StartExternalSession["Python"]value = ExternalEvaluate[session, "2+2"]IntegerQ[value]DeleteObject[session]Numbers, strings, lists and associations are automatically imported for the "Expression" return type:
session = StartExternalSession["Python"]result = ExternalEvaluate[session, "[2, 3, 'foobar', (1, 1)]"]Map[Head, result]DeleteObject[session]The return type of "String" returns a string of the result in the external language:
session = StartExternalSession["Python" -> "String"]result = ExternalEvaluate[session, "[1, 2, u'א']"]StringQ[result]DeleteObject[session]When using a database, the default return type is "Dataset":
db = DatabaseReference[FindFile["ExampleData/ecommerce-database.sqlite"]];session = StartExternalSession[db]ExternalEvaluate[session, "select officeCode as pk, phone from offices"]"ReturnType" can be used to return data in a different form:
sessionRows = StartExternalSession[{db, "ReturnType" -> "Rows"}];ExternalEvaluate[sessionRows, "select officeCode as pk, phone from offices"]sessionNamedRows = StartExternalSession[{db, "ReturnType" -> "NamedRows"}];ExternalEvaluate[sessionNamedRows, "select officeCode as pk, phone from offices"]sessionColumns = StartExternalSession[{db, "ReturnType" -> "Columns"}];ExternalEvaluate[sessionColumns, "select officeCode as pk, phone from offices"]sessionNamedColumns = StartExternalSession[{db, "ReturnType" -> "NamedColumns"}];ExternalEvaluate[sessionNamedColumns, "select officeCode as pk, phone from offices"]DeleteObject /@ {session, sessionRows, sessionNamedRows, sessionColumns, sessionNamedColumns};"Evaluator" (3)
Evaluate code using a specified "Evaluator":
session = StartExternalSession[
{"Python", "Evaluator" -> "/opt/homebrew/bin/python3"}]ExternalEvaluate[session, "import sys; sys.executable"]DeleteObject[session]An Association can be used to start a Python provisioned environment:
session = StartExternalSession[
{
"Python",
"Evaluator" -> <|
"Dependencies" -> {"emoji"},
"PythonRuntime" -> "3.11",
"EnvironmentName" -> "my-emoji-env"
|>
}
]Use the session to evaluate the code:
ExternalEvaluate[session,
"import emoji; import sys; [emoji.emojize('Emojis are :thumbs_up:'), sys.version, sys.executable]"]{"Emojis are 👍", "3.11.4 (main, Jul 5 2023, 08:41:25) [Clang 14.0.6 ]", "/Users/WolframUser/Library/Mathematica/ApplicationData/ExternalEvaluate/Python/Venv/my-emoji-env/bin/python"}DeleteObject[session]When using a File with the "SQL" evaluator, the target can be a path to an SQLite file or a DatabaseReference specification:
s1 = StartExternalSession[{"SQL", "Evaluator" -> FindFile["ExampleData/ecommerce-database.sqlite"]}];ExternalEvaluate[s1, "select officeCode, city from offices"]s2 = StartExternalSession[{"SQL", "Evaluator" ->
DatabaseReference[URL["postgres://localhost/template1"]]}];ExternalEvaluate[{"SQL", "Evaluator" -> s2 }, "SELECT NOW() as now, NOW()::date as date, interval '1 day' as interval, '1.23'::decimal as decimal"]DeleteObject /@ {s1, s2}"Name" (1)
Register an evaluator using a name:
RegisterExternalEvaluator[
"Python",
<|"Dependencies" -> {"numpy"}, "EnvironmentName" -> "my-numpy-env"|>,
"numpy-env"
]Start a session using the registered evaluator by referring to it by name:
session = StartExternalSession[{"Python", "Name" -> "numpy-env"}]ExternalEvaluate[session, "import numpy; numpy.arange(12)"]DeleteObject[session]"ID" (1)
Start an evaluator with a given "ID":
session = StartExternalSession[{"Python", "ID" -> "my-unique-id"}]The operation is idempotent; starting a session with the same "ID" will return the same running session:
StartExternalSession[{"Python", "ID" -> "my-unique-id"}]You can check that there is only one running session, even if you run StartExternalSession two times:
ExternalSessions[]DeleteObject[session]"SessionProlog" (2)
Use "SessionProlog" to perform a side effect at the start of a session:
session = StartExternalSession[{"Python", "SessionProlog" -> "print('session started')"}];ExternalEvaluate[session, "print('evaluating code'); 2+2"]DeleteObject[session]Start an external session and import a library at the beginning of the session:
session = StartExternalSession[<|"System" -> "Python", "SessionProlog" -> "import math"|>]Evaluate a function from the imported library:
ExternalEvaluate[session, "math.factorial(4)"]DeleteObject[session]"SessionEpilog" (1)
"Prolog" (1)
Use "Prolog" to perform a side effect before every evaluation:
session = StartExternalSession[{"Python", "SessionProlog" -> "n=0", "Prolog" -> "print('n was', n)"}];ExternalEvaluate[session, {"n += 3", "n += 3"}]DeleteObject[session]"Epilog" (1)
Use "Epilog" to perform a side effect after every evaluation:
session = StartExternalSession[{"Python", "SessionProlog" -> "n=0", "Prolog" -> "print('n was', n)", "Epilog" -> "print('n is', n)"}];ExternalEvaluate[session, {"n += 3", "n += 3"}]DeleteObject[session]Properties & Relations (5)
Each session runs in its own process:
sessions = Table[StartExternalSession["Python"], 2]The process IDs for each session are different:
ExternalEvaluate[#, "import os; os.getpid()"]& /@ sessionsDeleteObject[sessions]If only the language is specified, when possible, an evaluator is automatically provisioned:
session = StartExternalSession["Python"];session["Evaluator"]The evaluator is stored under $UserBaseDirectory:
ExternalEvaluate[session, "import sys; [sys.version, sys.executable]"]DeleteObject[session]Use ExternalEvaluators to find all available evaluators for a system:
evaluators = ExternalEvaluators["Shell"]Use StartExternalSession to start a session from it:
session = StartExternalSession[First @ evaluators]ExternalEvaluate[session, "ping -c 1 wolfram.com"]DeleteObject[session];db = DatabaseReference[FindFile["ExampleData/ecommerce-database.sqlite"]]session = StartExternalSession[db]ExternalEvaluate[session, "SELECT * from offices limit 5"]DeleteObject[session];External language cells implicitly call StartExternalSession:
ExternalSessions[]A new session has been started:
ExternalSessions[]By default, all cells of a given system use that session:
End the session so that subsequent evaluations start in a new session:
DeleteObject[Last[%%]]See Also
ExternalEvaluate ExternalSessions ExternalSessionObject ExternalEvaluators ExternalFunction ExternalObject StartProcess DeleteObject StartWebSession
External Evaluation Systems: Python NodeJS Julia Ruby R Shell Jupyter SQL SQL-JDBC CUDA
Related Workflows
Text
Wolfram Research (2017), StartExternalSession, Wolfram Language function, https://reference.wolfram.com/language/ref/StartExternalSession.html (updated 2026).
CMS
Wolfram Language. 2017. "StartExternalSession." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/StartExternalSession.html.
APA
Wolfram Language. (2017). StartExternalSession. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StartExternalSession.html
BibTeX
@misc{reference.wolfram_2026_startexternalsession, author="Wolfram Research", title="{StartExternalSession}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/StartExternalSession.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_startexternalsession, organization={Wolfram Research}, title={StartExternalSession}, year={2026}, url={https://reference.wolfram.com/language/ref/StartExternalSession.html}, note=[Accessed: 13-June-2026]}