Python - Group home

Why Python is the perfect development tool for you

  
Are you looking for a new language to quickly implement a project on z/OS? Are you looking for a language that is both simple to read and easy to maintain? Perhaps you want to speed up the development process without sacrificing reliability or scalability? 
 
If so, Python is the perfect tool for you. 
 
Let me explain.  
 
Python is a high-level, object-oriented programming language. It is one of the most utilized programming languages due to its impressive code readability. You can bring a powerful framework for building fast and scalable applications to z/OS and take advantage of Python’s rich ecosystem of modules and packages to develop new applications with a shorter delivery time compared to other languages.  
 
Here are some ways to use Python on z/OS. 
 

Data Manipulation:  
Python makes working with a large collection of data much easier. Imagine you are trying to read a spreadsheet, but the output is too unorganized and difficult to work with—in other words, a disaster waiting to happen. Using Python, however, enables one to easily sift through the data and produce an easy solution.  
 
Here is what Python, with a package called Pandas, can produce: 
 
>>> import pandas as pd  
>>> pd.read_csv("./test.csv")  
    col1 col2 col3  
0   a    b    c  
1   3    4    5   ​

Notice how simple it is to start—a main advantage to using Python. Python is focused on simplicity as well as readability, providing a variety of helpful options for any work in data analysis. You can build a solution with simple syntax and fewer lines for even a complex scenario. Here is an example showing how easy it is to write to a csv file: 
 

>>> import pandas as pd  
>>>cities = pd.DataFrame([‘Canada’, ‘Ottawa’], [‘the United States’, ‘Washington, DC’], columns=[‘Country’, ‘Capital City’]) 
>>> cities.to_csv(‘cities.csv’) 
>>>pd.read_csv(‘./cities.csv’) 
         Country                 Capital State 
0        Canada                  Ottawa  
1        the United States       Washington, DC ​

Python is also well supported, meaning there is a wide range of libraries for one to choose from and utilize. Other than Pandas, which was mentioned above, there is NumPy for more complex mathematical calculations, Matplotlib for creating static, animated or interactive visualizations, or StatsModels for statistical modeling. Overall, if your work involves any type of data analysis, Python will provide you more than enough tools for you to do your work efficiently. 
 

Web Development:  
How about web-related projects? Python has its own web application framework, Flask being one of them. Flask is an easy-to-use web framework written in Python. It provides one with tools for building web applications such as blogs, websites, or any other application hosted on the internet. Here is a sample code snippet on how to set up a simple webpage: 
 

from flask import Flask 
 
app = Flask(__name__) 
 
 
@app.route('/') 
def hello(): 
    return 'Hello, World!' ​

Once again, notice how simple and straightforward it is to get a webpage up and running with Python—essentially, any web-related task can be accomplished using this language. This enables anyone to build anything they would like on the web, such as serving a custom restful interface or presenting reporting data.  If you’d like to host a full stack web application, with access to the db2 database at IBM, this is fully supported by Python. This brings us to our next point. 
 
Database Access: 
Whether you are planning to host a full stack web application or keep track of any data you have collected, you will need to access a database. Python is perfect for this task as well. There are multiple ways to connect Python to the db2 database, the 2 most popular choices being ibm_db and jaydebeapi. Both packages connect Python to the db2 database and allows one to run SQL queries. It is worth noting that ibm_db uses odbc which can support type 2 connections, and jaydebeapi offers a JDBC path. By doing so, one is able to connect Python running on z/OS with the db2 database without it ever leaving the system.   
 
For more information, see this blog post
 
IBM Z Open Automation Utilities 
IBM Z Open Automation Utilities, also known as ZOAU, is a set of tools designed to help bridge the gap between a traditional z/OS system and IBM z/OS Unix System Services by providing equivalent utilities to many Unix commands that can operate on z/OS specific file types such as dls –dataset ls, dtouch –dataset touch and dcp –dataset cp. Python users on z/OS often use this tool to directly work with z/OS datasets. Let’s see how simple it is to create a dataset and write to it using ZOAU. 
 

>>> from zoautil_py import Datasets 
>>> Datasets.create("EXAMPLE", type="SEQ") 
0 
>>> Datasets.write("EXAMPLE", "Hello world.") 
0 ​

All one needs to do is import Datasets from zoautil_py; then, you will have all the functions needed for these tasks. How about reading from a dataset?  
 

>>> from zoautil_py import Datasets 
>>> Datasets.read("EXAMPLE") 
Hello world. ​


Again, notice how simple it is to use Python on z/OS specific tasks. All the tools needed are simple and straightforward. If you are interested in trying this yourself, here is the link to ZOAU documentation for more information: 


https://www.ibm.com/docs/en/zoau


Streamline Automation:  
You can also use Python to set up an automated process. For example, you can automate applications and IT infrastructure using Ansible, configuration-management software which is most notably used to automate machine setup. With just a few instructions, one can connect the control node to the target machine and have all the steps required for configuring the target machine automated. One huge advantage of using Ansible is its reliability and minimal learning required. The Ansible Playbooks use an easy and descriptive language. If Ansible is something you are interested in using for your project, Python is your only option, since Ansible only supports Python.  
 

Continuous Integration 
Do you have multiple developers working on the same project(s)? Are you worried about integration conflicts? Why not have your build self-compiling and self-testing?  
 
One tool you can use for this is buildbot. It automates the “compile and test” cycle of the project source code by simplifying and modernizing the compilation and testing phases. One single command will enable one to build their whole project, and all test cases will run to confirm it behaves as expected.  
 
If you’d like to simplify the process even more, one can even set up a nightly scheduler, which is responsible for initiating builds and tests every night. Again, notice how simple it is to have a tool set up for continuously building and testing your project. With this tool, all integration bugs are detected early and are easy to track down due to a smaller set of changes. This tool speeds up the development process and ensures reliability.  
 
 
And there you have it. Python is the perfect language to use for any project on z/OS you have in mind. If you are interested in knowing more about Python on z/OS, here is the link for more information:  
 
https://www.ibm.com/products/open-enterprise-python-zos