Python (Jython) Scripting in Ignition
Key Takeaway
Guide to Python scripting in Ignition — script types, the system.* API, gateway vs. client scope, project library scripts, and debugging techniques.
Quick Answer
Ignition uses Jython (Python 2.7 running on the JVM) for all
scripting. Scripts can run on the gateway, in client sessions, or in
the Designer. Ignition provides a comprehensive system.* API
for database access, tag operations, alarm management, HTTP requests,
file I/O, and user interaction.
Scripting Contexts
Understanding where a script runs is critical in Ignition:
- Gateway Scope — Timer scripts, tag change scripts,
message handlers, and alarm pipeline scripts run on the server.
They have no access to client GUI functions but can use
system.db,system.tag,system.alarm, andsystem.net. - Client Scope — Component event scripts and client
event scripts run in the operator's session. They can access GUI
functions like
system.gui(Vision) orsystem.perspective(Perspective). - Designer Scope — Scripts in the Designer's scripting console run in the Designer's JVM. Useful for testing and prototyping.
Common System Functions
# Read a tag value
value = system.tag.readBlocking(["[default]Tank/Level"])[0].value
# Write a tag value
system.tag.writeBlocking(["[default]Pump/Start"], [1])
# Run a database query
results = system.db.runQuery("SELECT * FROM production WHERE date = ?",
[system.date.now()], "ProductionDB")
# Send an HTTP request
response = system.net.httpGet("https://api.weather.com/conditions")
# Log to the gateway console
system.util.getLogger("MyScript").info("Process completed")
Project Library Scripts
Reusable functions should be placed in the project's Script Library (Project > Script Library in the Designer). These modules are accessible from any script context using the project name prefix:
# In Script Library module "utils"
def calculateFlowRate(dp, density, area):
import math
return area * math.sqrt(2 * dp / density)
# Called from any script
rate = project.utils.calculateFlowRate(15.2, 840, 0.0314)
Debugging Techniques
- Use the Script Console in the Designer for interactive testing.
- Use
system.util.getLogger()to write to the gateway logs, viewable in Status > Logs. - Use
print()statements for Designer output — these appear in the Designer's output console. - Check the Script Diagnostics page in the gateway for script errors, execution times, and call counts.
Frequently Asked Questions
Ignition uses Jython, which implements Python 2.7 on the Java Virtual Machine. This means standard Python 2.7 syntax and most of the standard library are available, plus access to Java classes.
Not natively. Ignition's built-in scripting engine is Jython (Python 2.7). However, you can call external Python 3 processes via system.util.execute() or invoke REST APIs served by Python 3 applications.
The system.* namespace provides built-in functions for tag operations, database queries, alarming, HTTP requests, date handling, file I/O, and GUI interactions. It is the primary API for Ignition scripting.