Products Resources Support About Us

Calling z/OS services in python

I was thinking about how convenient it would be if I could call z/OS system services, e.g. IEFSSREQ, from within a python program. I’ve been thinking about it and doing a little research, and I think it would be possible to do this… But I was hoping I could get some advice from Rocket or other users of this forum before I proceed any further.

Here’s the approach I was thinking of taking…

  1. CPython (which I believe the Rocket version of python is a port of) can be extended with “extension modules” that are written in C. I was going to use this documentation for guidance:

  2. Next, the z/OS XL C compiler supports a #pragma that can be used for interlanguage function calls. As a part of this, I would have to create a “stub routine” which would be the glue between the C program and the z/OS service in question. Documentation about the pragma on this page:

I’d appreciate any feedback or suggestions about this approach before I invest a lot of time into it. Or maybe there’s an easier way that I am not thinking of.

Another alternative which avoids writing Python extension modules, could be the built-in foreign function library: the ‘ctypes’ module.

It allows to load external DLLs (load modules) and define parameters to be used for the call to its entry points. But to use it for z/OS system services it depends on whether there is a system DLL that provides the functionality.

It would be good to have more z/OS specific functionality available for Python including record I/O…


This is admittedly not exactly what you’re asking, but you may find this interesting:


Does anyone know whether MVS cmds issued using Python code like REXX? This is in reference to “Python for z/OS” V3.6.

Thought I would share a useful link that an IBMer wrote about creating python extensions on z/OS:

I am successfully using the IBM xlc compiler’s embedded assembly support to call z/OS services in the python extension module.