API Environments
Ver
:
Plugins in Sublime Text are Python files located in the root of a package. The following document describes the Python environment the plugins are run in.
Overviewπ
Sublime Text runs plugins in a separate process from the main editor UI. This process runs an executable named plugin_host.
Running plugins in a separate process ensures the entire editor will not crash due to a poorly written plugin. If a plugin does cause the plugin_host to crash, a user may still save their work before re-starting Sublime Text.
All plugins are run in a single plugin_host process, and share a single
Python environment. Each plugin is loaded as a sub-module of a module named
after the package. For example, a plugin in the
file MyPackage/my_plugin.py will be loaded as the Python module
MyPackage.my_plugin
.
The plugin_host process contains an embedded version of the Python programming language, and exposes an API to plugins. The plugin_host executable always uses its own embedded version of Python, even if the end-user has Python installed on their machine.
Python Versionπ
By default all plugins are run using Python 3.3.6, except inside the
User package which always uses the latest python. Sublime Textβs build
of Python 3.3.6 includes a handful of patches backported from Python 3.4 to fix
issues with unicode paths and crashes with the ctypes
module on 64bit
versions of Windows.
Starting in build 4050, plugins may also be run using Python 3.8. Python 3.8 features many improvements to the language, better performance and continued support and bug fixes from the Python Software Foundtion.
4050Selecting the Python Versionπ
To provide for backward compatibility, Sublime Text 4050 will continue to run all plugins using Python 3.3.
Any package that wishes to use Python 3.8 must create a file
named .python-version in the root of the packages. This file should
contain either the text 3.3
or 3.8
to select the version of Python to
use. If a file named .python-version is not present, or it contains
any value other than 3.8
, then Python 3.3 will be used.
All plugins in a package will use the same version of Python. Any package with
a .python-version file containing 3.8
loaded in older builds of
Sublime Text will try to run the plugins using Python 3.3.
Modulesπ
The Python environment within plugin_host contains all of the modules in The Python Standard Library, except for:
audioop
crypt (Not on Linux)
curses
cProfile (Not on Linux) <4050
fpectl 4050 3.3
readline
lzma 4050 3.3
msilib
nis
ossaudiodev
resource 4050 3.3
spwd
syslog
test
tkinter
turtle
wave