The main xonsh script.

class xonsh.main.XonshMode(value)[source]#

An enumeration.

interactive = 3#
script_from_file = 1#
script_from_stdin = 2#
single_command = 0#

Proxy function for loading process title


Generator that runs pre- and post-main() functions. This has two iterations. The first yields the shell. The second returns None but cleans up the shell.


Main entry point for xonsh cli.


Return a path only if the path is actually legal (file or directory)

This is very similar to argparse.FileType, except that it doesn’t return an open file handle, but rather simply validates the path.


Teardown for main xonsh entry point, accepts parsed arguments.


Setup for main xonsh entry point. Returns parsed arguments.

xonsh.main.setup(ctx=None, shell_type='none', env=(('RAISE_SUBPROC_ERROR', True),), aliases=(), xontribs=(), threadable_predictors=())[source]#

Starts up a new xonsh shell. Calling this in function in another packages __init__.py will allow xonsh to be fully used in the package in headless or headed mode. This function is primarily indended to make starting up xonsh for 3rd party packages easier.

Here is example of using this at the top of an __init__.py:

from xonsh.main import setup
del setup
ctxdict-like or None, optional

The xonsh context to start with. If None, an empty dictionary is provided.

shell_typestr, optional

The type of shell to start. By default this is ‘none’, indicating we should start in headless mode.

envdict-like, optional

Environment to update the current environment with after the shell has been initialized.

aliasesdict-like, optional

Aliases to add after the shell has been initialized.

xontribsiterable of str, optional

Xontrib names to load.

threadable_predictorsdict-like, optional

Threadable predictors to start up with. These overide the defaults.

xonsh.main.start_services(shell_kwargs, args, pre_env=None)[source]#

Starts up the essential services in the proper order. This returns the environment instance as a convenience.