OpenSite/Guides/Run your first script
Run a small Python calculation and learn which output surface to read.
- Stable identifier
opensite.help.run-your-first-script
Prerequisites
An OpenSite development build with its matching embedded runtime. A system Python interpreter is not a replacement for the embedded OpenSite host.
Steps
Choose console or editor
Use the interactive Console for a short expression. Use the Python workbench editor for a repeatable .py file. They share one interpreter and lane.
Enter the quantity lesson
Create a script containing the quantities example below. Save it before relying on its filename in tracebacks. Running an unsaved buffer does not save it.
Run the current file
Choose the Python workbench Run action. The workbench also supports running a selection or a current line; verify the intended scope before running.
Read Output
Workbench script stdout/stderr goes to the host Output panel, with source python.script. The interactive Console transcript is separate. View → Show Output shows the shared panel.
Repeat deliberately
Rerun retains imports, variables and application state. Start with a fresh document or explicit variables when the example depends on a clean state.
Expected result
The quantity lesson reports a total of 3650 mm. The same script can be used in the matching headless OpenSite host.
Limitations
A script has the privileges of the embedded host. Run only trusted code. Avoid starting a second operation while the shared execution lane is busy.
Complete example
import opensite
span = opensite.parse_quantity("3.2 m")
extension = opensite.parse_quantity("450 mm")
total = opensite.add(span, extension)
print(f"Total: {total.value_in('mm'):.0f} mm")
assert abs(total.si_value - 3.65) < 1e-12
before = total.si_value
opensite.execute("units.set_profile", {"profile": "engineering_metric"})
print("Display:", opensite.format_quantity(total, "engineering_metric"))
assert total.si_value == before