![]() |
Shotgun Python ConsoleA Python console for Shotgun Toolkit |

Documentation
Panel
Tabs
Editor
Output
Buttons
Output
Editor
Globals
External sources
Hotkeys
Other notes
Installation, Updates and Development
Configuration Options
Release Notes History
This application provides an interactive python console for any environment that runs Toolkit applications.
Documentation
This is a python console panel for use in DCCs with access to a python interpreter that have limited or no support for interacting with said interpreter.
Python Console in Photoshop CC 2017
Python Console in Flame
Panel
Once installed, the console is registered as a panel in the DCC and is available in the Shotgun menu. In apps that support embedded Toolkit panels (maya, nuke, houdini), the console will display in a docked panel. When using with older versions of these DCCs or in a DCC that does not support panels, the console will simply be shown as a regular Toolkit dialog.
Tabs
The python console displays one or more tabs, each containing an editor and an
output window. New tabs can be created by clicking the +
button in the bottom
right hand corner. Tabs have an x
button next to the tab name that allow you
to delete the tab. Double clicking the tab itself will prompt you to enter a
new name for the tab. Tabs can be rearranged via drag and drop. The state of the
tabs is saved when the DCC is closed and restored on the next launch.
Editor
The console has an input area for editing python. The editor includes line numbers, highlights the cursor's current line, and does some basic syntax highlighting. The console attempts to use the palette of the DCC to give it an integrated look and feel.
Block indenting and unindenting is supported. Select one or more lines and press tab
to indent by four spaces or shift + tab
to unindent by four spaces. It tries to keep the indentation in blocks of four so it will indent/unindent to the nearest whole block of four spaces.
Block commenting and uncommenting is also supported. Select one or more lines and press cmd + /
on Mac, ctrl + /
for Windows and Linux. If any of the selected lines don't have a #
at the start it will add one to all selected lines. If all the lines do have a #
, then it will remove them.
Output
The output area displays the results of the executed python. Echoing the source
python commands is turned on by default and is differentiated in the output by
being prefixed with >>>
. Each execution is also marked with a timestamp. There
is a toggle for turning the echo off. Syntax and Runtime errors are shown in red
with a full stack trace for debugging.
Buttons
Output
- Clear - Clear the contents of the output browser.
- Echo - Toggle echoing the executed commands in the output browser.
Editor
- Execute - Execute the contents of the editor
- Save - Save the current contents of the editor to a file.
- Open - Open a file in the editor.
- Clear - Clear the contents of the editor.
- Lines - Toggle line numbers for the current tab
Globals
Some Shotgun/Toolkit globals are pre-defined in the console, similar to what is available in the Shotgun Engine for the shell.
- Tk API handle is available via the
tk
variable - Shotgun API handle is available via the
shotgun
variable - The current context is stored in the
context
variable - The shell engine can be accessed via the
engine
variable
External sources
The app comes with a hook that can be implemented to load python source from an
external location. The hook is called external_sources_hook
and requires
implementing a method called get_external_source_actions
. The method should
return a list of QActions
that, when triggered, add a new tab (with content)
to the console. An example implementation is provided that loads gists from
github for a list of predefined users. The actions returned by the hook are
shown in the popup menu displayed when the Open button is pressed and held.
Hotkeys
- Execute selected with
Ctrl + Enter
- Create a new tab with
Ctrl + T
- Navigate tabs with
Ctrl + Shift + [
orCtrl + Shift + ]
- Resize input/output font via
Ctrl + Wheel
NOTE: These hotkeys may not be available in all DCCs.
Other notes
- In some older versions of DCCs, leaving the python console open when closing the session may cause a crash. We believe this may be a bug in some older versions of PySide. More recent versions of DCCs, bundled with newer versions of PySide, do not appear to crash on exit. If you encounter this issue with a recent DCC release, please submit a ticket so that we can investigate further.
Installation and Updates
Adding this App to the Shotgun Pipeline Toolkit
If you want to add this app to Project XYZ, in an environment named asset, execute the following command:
> tank Project XYZ install_app asset tk-maya tk-multi-pythonconsole
Updating to the latest version
If you already have this item installed in a project and you want to get the latest
version, you can run the update
command. You can either navigate to the
tank command that comes with that specific project, and run it there:
> cd /my_tank_configs/project_xyz > ./tank updates
Alternatively, you can run your studio tank
command and specify the project
name to tell it which project to run the update check for:
> tank Project XYZ updates
Collaboration and Evolution
![]() |
If you have access to the Shotgun Pipeline Toolkit, you also have access to the source code for all apps, engines and frameworks in Github where we store and manage them. Feel free to evolve these items; use them as a base for further independent development, make changes (and submit pull requests back to us!) or simply tinker with them to see how they have been built and how the toolkit works. You can access this code repository at https://github.com/shotgunsoftware/tk-multi-pythonconsole. |
Special Requirements
- You need Shotgun version v6.2.0 or higher to use this.
- You need Shotgun Pipeline Toolkit Core API version v0.19.1 or higher to use this.
Configuration
Below is a summary of all the configuration settings used. These settings need to be defined in the environment file where you want to enable this App or Engine.
external_sources_hook
Type: hook
Default Value: {self}/external_sources.py
Description: Supplies information about external sources for new tabs.
Release Notes
Welcome to the release notes for this App. Below you will find an overview of all the changes we did for each release. We try to be as detailed as possible and include all bugs we have fixed, features we have added and things that may have changed. If you have questions about a particular release, don't hesitate to contact our support team!
v1.2.5
2020-Nov-19
Fixes an issue with the stack trace not being displayed when the executed code errors in the Python console. This only occurred when running the Python console outside of a Shotgun Engine.
v1.2.4
2020-Sep-27
Fixes a crash in RV when an exception is thrown in the python console. Updates the colour scheme to fixed colour values to keep the look consistent across DCCs.
v1.2.3
2020-May-19
Fixes the comment hotkey.
Details:
Now only comments the line out when holding ctrl/cmd + /
instead of just /
.
v1.2.2
2020-Mar-24
New features:
Details:
- Adds block indenting and unindenting. You can select multiple and press
tab
orshift + tab
to indent and unindent the selected lines without removing the contents. - Adds block commenting and uncommenting. You can select multiple lines and press
cmd + /
on Mac, orctrl + /
on Linux to add or remove#
characters from the start of each line. If at least one of the selected lines doesn't start with a#
then it will comment the selection, otherwise if all selected lines have a#
it will uncomment the lines. - Pressing return on a line will start the next line at the same level of indentation, unless you are pressing return after a
:
character, in which case it will indent the next line by an additional four spaces. - Saving a script now defaults to a
.py
extension. - The selected line highlight has been now toned down a little and the comments brightened a little to make the text more readable.
v1.2.1
2020-Feb-13
Fixes a bug with the global scope of executed code.
Details:
Fixes a bug where methods run in the Python console could not access the global scoped variables.
For example, importing a module and then using it within a method would throw a NameError
before the fix. Huge thanks to Joe Hultgren for providing this fix.
v1.2.0
2020-Feb-11
Python 3 support
Details:
- It now works in Python 3. As a result, the required core has been bumped to v0.19.1
and it now requires Shotgun utils v5 up from v4.
- Small bug fix for situations where the open file button would throw an error.
- Using the python console standalone, (without sgtk
being present,) is still supported but it is recommended that you install the module six
so that it can better handle strings.
v1.1.2
2018-Mar-14
Bug fix
v1.1.1
2017-Aug-18
Changes to allow the app to run independently of toolkit
v1.1.0
2017-May-16
Moves the python console menu item from the main menu to the context menu.
v1.0.9
2017-Mar-15
Removes problematic profiles from png files used as icons.
Details:
This will silence libpng warnings from Qt when the png files are loaded as pixmaps. This is a second attempt as this profile stripping, and uses ImageMagick's "mogrify" command to achieve the desired result, which maintains color consistency.
v1.0.7
2017-Feb-08
Use active window for dialog parenting
v1.0.6
2017-Feb-08
Bug fix for both echo output and show lines toggles
v1.0.5
2017-Feb-07
QA fixes for toggle echo and line numbers
v1.0.4
2017-Feb-07
QA fixes for dialog parenting
v1.0.3
2017-Feb-07
Removed unnecessary minimum width
v1.0.2
2017-Feb-07
Do not use native file dialogs. Fixes issues in photoshopcc engine
v1.0.1
2017-Feb-07
Updated docs, external sources hook is no-op by default
v1.0.0
2017-Feb-06
QA fixes
v0.0.3
2016-Jul-13
Bug fixes, tabs, external resources, and more
v0.0.2
2016-Jun-29
bug fixes, tabs, external resources, and more
v0.0.1
Initial release