When we hear the word Mainframe, the first technologies that usually come to mind are COBOL, JCL, DB2, VSAM, and CICS.
But did you know that Python can also run on IBM Mainframe systems running z/OS?
Yes! Python is supported on IBM z/OS, and developers can use it for scripting, automation, data processing, and integration with other systems.
In this article, we will understand:
- What Python on z/OS means
- Where we can write Python programs on Mainframe
- How to execute Python interactively
- How to execute Python using JCL
- A practical example of running a Python program as a batch job
- Some important things to remember
Let’s get started!
1. Can Python Run on IBM Mainframe?
Yes, Python can run on IBM z/OS.
IBM provides IBM Open Enterprise SDK for Python, which allows developers to run Python programs on z/OS.
Unlike traditional Mainframe programs that commonly work with MVS datasets, Python on z/OS primarily runs inside z/OS UNIX System Services (USS).
What is USS?
USS stands for UNIX System Services.
It provides a UNIX-like environment within z/OS. You can work with:
- UNIX directories and files
- Shell commands
- Python scripts
- Executable programs
- Environment variables
For example, you can create directories such as:
/u/ankit/python/
And store Python programs inside them:
/u/ankit/python/hello.py
Think of USS as a UNIX-like environment available within your Mainframe system.
2. Where Can We Write Python Code on Mainframe?
There are different ways to access and work with Python on z/OS.
Option 1: Using ISPF and USS
Many Mainframe developers are familiar with ISPF.
You can use ISPF to navigate and work with datasets, but Python scripts are generally stored as files in the USS filesystem.
A typical approach is:
- Open ISPF.
- Navigate to the option that allows access to UNIX System Services, if available.
- Open the USS directory using the available interface or shell.
- Create a Python file.
- Write your Python code.
- Execute it using the Python interpreter.
For example:
/u/ankit/python/hello.py
You can also create or edit USS files using supported ISPF utilities or other available editors.
Important: A Python script stored in USS is different from a Python program stored as a member of a traditional PDS or PDSE.
Option 2: Using the OMVS / UNIX Shell
You can access the z/OS UNIX shell from TSO using the OMVS command, provided it is enabled for your user.
Steps:
1) Type s TSO mvsd and then hit enter
2) Type OMVS and then hit enter
here mvsd is the environment name, in your case environment name might be different.
Once inside the shell, you can execute UNIX commands.
For example:
pwd
To check your current directory.
ls
To list files.
cd /u/ankit/python
To navigate to your Python directory.
This environment is where you can execute Python commands.
3. How to Check Whether Python Is Available on z/OS?
Before executing Python programs, you need to check whether Python is installed and accessible.
From the USS shell, execute:
python3 --version
Or, depending on your installation:
python --version
Example output:
Python 3.12.x
The actual Python version depends on the SDK installed and configured by your organization.
If the command is not recognized, Python may not be installed or its executable directory may not be included in your PATH.
In an enterprise environment, installation and configuration are generally handled by the Mainframe system administration team.
4. How to Execute Python Code on Mainframe?
Let’s start with a simple example.
Create a Python file named:
hello.py
Write the following code inside it:
print("Hello from IBM Mainframe!")
print("Python is running on z/OS")
Save the file in your USS directory.
For example:
/u/ankit/python/hello.py
Now open the USS shell and execute:
python3 /u/ankit/python/hello.py
Output:
Hello from IBM Mainframe!
Python is running on z/OS
That’s it!
You have successfully executed a Python program on IBM Mainframe.
5. Can We Execute Python Using JCL?
Yes!
This is one of the most interesting things about Python on Mainframe.
Just like COBOL programs, Python programs can also be executed as batch jobs using JCL.
For this purpose, we can use a utility called: BPXBATCH
What is BPXBATCH?
BPXBATCH is a z/OS utility that allows you to execute UNIX programs and shell commands from a batch environment.
In simple terms:
- COBOL programs can be executed using JCL.
- Python programs can also be executed using JCL.
- BPXBATCH helps connect JCL with the USS environment.
This makes Python useful for scheduled processing and automation on Mainframe.
6. Practical Example: Execute Python Using JCL
Let’s understand this with a simple example.
Step 1: Create a Python Program
Create a Python file named:
hello.py
Location:
/u/ankit/python/hello.py
Python code:
import sys
print("Hello from Python on Mainframe!")
print("This is executed using JCL")
print("Python batch job completed successfully")
Save the file.
Step 2: Create JCL
Now create a JCL job that executes the Python program.
//PYTHON JOB
//STEP1 EXEC PGM=BPXBATCH,
// PARM='sh /u/ankit/python/usr/lpp/IBM/python/v3r12/pyz/bin/python3 /u/ankit/python/hello.py'
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
Note: The Python installation path shown above is an example. Replace it with the actual installation path available in your Mainframe environment. The Python version may also differ.
Step 3: Submit the JCL
Submit the JCL using your normal Mainframe job submission process.
For example, from ISPF:
SUB
Or use your organization’s job submission tool.
Step 4: Check Job Output
After the job completes, check the output in SDSF or your organization’s job monitoring tool.
Expected output:
Hello from Python on Mainframe!
This is executed using JCL
Python batch job completed successfully
Congratulations!
You have now executed a Python program using JCL on IBM z/OS.
7. What Are the Different Ways to Run Python on z/OS?
Let’s summarize the execution methods.
| Method | Purpose |
|---|---|
| USS Shell | Execute Python commands interactively |
| Python Script | Run a .py file from USS |
| TSO / OMVS | Access the USS environment |
| JCL + BPXBATCH | Execute Python as a batch job |
| Scheduler + JCL | Schedule Python batch processing |
For production workloads, Python can be integrated into existing Mainframe batch workflows.
For example:
Scheduler
|
v
JCL Job
|
v
BPXBATCH
|
v
Python Program
|
v
Process Data / Generate Output
This is especially useful when Python needs to participate in an existing enterprise batch process.
8. Can Python Access Mainframe Datasets?
Yes, Python can work with Mainframe data, but the approach depends on the type of dataset and the interface being used.
For example:
- USS files can be accessed using Python file operations.
- Sequential datasets and partitioned datasets require suitable interfaces or utilities.
- DB2 data can be accessed through supported database connectivity options.
- Data can also be transferred between MVS datasets and USS files.
A common approach is to use existing Mainframe utilities to transfer or convert data before processing it with Python.
Remember that MVS datasets and USS files are not the same thing.
For example:
MVS Dataset:
ANKIT.TEST.DATA
USS File:
/u/ankit/python/data.txt
Python’s standard file operations work naturally with USS files. Accessing MVS datasets directly may require additional tools or libraries.
9. What Are the Use Cases of Python on Mainframe?
Python can be useful in several scenarios.
Data Processing: Python can process files, transform records, validate data, and generate reports.
Automation: Python can automate repetitive activities and execute utility commands.
Database Integration: Python can connect to supported databases and execute SQL queries using appropriate libraries.
File Validation: Python can validate data files before loading them into downstream systems.
Batch Processing: Python scripts can be executed through JCL and integrated into existing batch workflows.
Integration with Modern Technologies: Python can help connect Mainframe applications with APIs, cloud platforms, and other modern technologies.
10. Important Things to Remember
Before running Python on Mainframe, keep these points in mind:
- Python must be installed and configured on the z/OS system.
- You need access to USS.
- You must know the Python installation path.
- Your user needs the required permissions.
- Python scripts are generally stored in USS.
- JCL execution requires proper BPXBATCH configuration.
- Some Python packages may require additional dependencies or compatible builds.
- Production execution should follow your organization’s security and scheduling standards.
Conclusion
Python is no longer limited to Linux, Windows, or cloud platforms.
With IBM Open Enterprise SDK for Python, developers can execute Python programs on IBM z/OS.
You can write Python scripts in USS, execute them from the UNIX shell, and even run them as batch jobs using JCL and BPXBATCH.
For Mainframe developers who are learning Python, this opens up new opportunities to combine traditional Mainframe processing with modern programming capabilities.
If you are a Mainframe developer familiar with COBOL, JCL, DB2, and datasets, learning Python on z/OS can be a valuable addition to your skill set.
Keep learning and keep exploring!
References
- IBM Open Enterprise SDK for Python: https://www.ibm.com/products/open-enterprise-sdk-python
- IBM Documentation – Installing Python on z/OS: https://www.ibm.com/docs/en/python-zos
- IBM Documentation – Processing Work on z/OS: https://www.ibm.com/docs/en/zos-basic-skills