Python cells
Hex’s first-class Python support unlocks a world of opportunity for data exploration.
- Users will need Can Edit permissions.
Developing logic in Python cells
Users can write, edit, and execute any valid Python in a Python cell. For inspiration, check out our Use case library to browse example Hex projects.
Adding and editing a cell
Click the Add cell button and select Python to add a new Python cell to your project. Write your Python script in the cell and click the Run button to execute it.
Users can edit and execute any valid Python in a Python cell.
Importing packages
Hex projects come pre-installed with a number of Python packages, which you can view in the Environment tab of the left sidebar. Use an import
statement to load the package into your project.
If the package you need is not already installed, add a new Python cell and use a !pip install
command. Import the package as you normally would to use it in your project.
Hex frequently updates the pre-installed packages and versions. If your team requires specific package versions, importing from GitHub or using Custom images may be appropriate.
Outputs
Python cells can optionally have outputs, which are visualizations of elements from the code.
If any line of a Python cell explicitly prints a value (e.g: print("hello!")
), that value will be included in the Output along with any other values explicitly printed by other lines.
Lines that implicitly print a value (e.g: 2+2
) are only included in output if they occur on the last line of a Python cell.
If a cell has no explicit print statements and the last line does not print a value explicitly or implicitly (e.g: x = 5
), nothing is displayed as output. This is perfectly fine, and is often done to keep things readable while setting the stage for another cell that will display something.
Converting cells
You can convert a cell from a Python to a Markdown cell and vice-versa using the dropdown in the upper right.
Or use keyboard shortcuts to convert between cell types:
- Go from Python to Markdown cells with
esc + m
- Go from Markdown to Python cells with
esc + y