Skip to content
Back to top
View this page
Edit this page

# Xonsh API

The `xonsh.api` package is a set of public libraries that can be used in third-party projects as well as in xonsh extensions (xontribs). If you are writing a xontrib, using `xonsh.api` is the recommended way to interact with xonsh internals.

Warning

The API is under development and currently has a small number of methods. Contributions are welcome!

For the full internal library reference, see Xonsh Library.

## `xonsh.api.subprocess`

Drop-in replacements for `subprocess` functions that use xonsh’s subprocess pipeline under the hood.

xonsh.api.subprocess.run(cmd, cwd=None, check=False)

  Drop in replacement for `subprocess.run` like functionality

xonsh.api.subprocess.check_call(cmd, cwd=None)

  Drop in replacement for `subprocess.check_call` like functionality

xonsh.api.subprocess.check_output(cmd, cwd=None)

  Drop in replacement for `subprocess.check_output` like functionality

## `xonsh.api.os`

Xonsh-powered utilities inspired by the `os` module.

xonsh.api.os.rmtree(dirname, force=False)

  Remove a directory, even if it has read-only files (Windows). Git creates read-only files that must be removed on teardown. See https://stackoverflow.com/questions/2656322 for more info.

  Parameters:
    dirname str

      Directory to be removed

    force bool

      If True force removal, defaults to False

xonsh.api.os.indir = <function with_pushd>

  alias to push_d context manager