Power

 View Only
  • 1.  Getting started with Python on the IBM Power system

    Posted Mon March 03, 2025 07:37 PM

    Greetings,

    My employer started offering Python training through a college that we have a relationship with. My goal is after the training I'd like to play with Python on our Power 10 server. I've already installed Python on one of our LPARs.

    I'm wondering if anyone can recommend some good tutorials for Python that pertain to the IBM i.  I found this IBM page that gives an example of reading a DB2 table using Python.  

    Python script accessing DB2 data - Simple example

    I tried to do the example shown on the web page, but seem to be getting errors running the Python script I created.  I also am not 100% sure I installed PTable correctly.  

    Lastly the training course I'm taking through work has us doing our Python training using Microsoft VS Code.  I'm wondering can you run Python code in VS Code that accesses data on the IBM i?

    Thank you,

    Michael Soucy



    ------------------------------
    Michael Soucy
    ------------------------------


  • 2.  RE: Getting started with Python on the IBM Power system

    Posted Wed March 05, 2025 04:56 AM

    Hi Michael, I am by no means knowledgeable regarding Python, but have you looked for related info here:
    Python - Tutorials - IBM Developer 

    Regards,
    Mark



    ------------------------------
    Mark Mather
    ------------------------------



  • 3.  RE: Getting started with Python on the IBM Power system

    Posted Wed March 05, 2025 10:32 AM
    Edited by Marius le Roux Wed March 05, 2025 10:35 AM

    Hi Michael, 

    (assuming you are running the Python on IBMi itself)

    Here are a great few resources for you to try : 

    https://www.itjungle.com/2019/06/10/guru-getting-started-with-python-on-ibm-i/

    https://github.com/IBM/ibmi-oss-examples (good examples here also for you to try out) 

    This is also a goto resource for you to evaluate (an official link for any IBM i Open Source)  :

    https://ibmi-oss-docs.readthedocs.io/en/latest/python/README.html


    Then do you perhaps know of the IBM I Open Source community on Ryver? (there you will  be able to post your questions for a great deal of Python experts)

    https://ibmioss.ryver.com/ 

    http://ibm.biz/ibmioss-chat-join <--- to join 

    Give your question there a stab to see if people might be able to help you troubleshoot? 



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Consultant & Technology Strategist
    MLR Consulting
    Port Alfred
    ------------------------------



  • 4.  RE: Getting started with Python on the IBM Power system

    Posted Wed March 05, 2025 10:41 AM
    Edited by Marius le Roux Wed March 05, 2025 10:43 AM

    "Microsoft VS Code.  I'm wondering can you run Python code in VS Code that accesses data on the IBM I?" <---- on this part , this does work most definitely because of the ODBC support for IBM I , just make sure you have the latest ODBC drivers from ACS installed on your system : https://www.ibm.com/support/pages/ibm-i-access-client-solutions



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Consultant & Technology Strategist
    MLR Consulting
    Port Alfred
    ------------------------------



  • 5.  RE: Getting started with Python on the IBM Power system

    Posted Thu March 06, 2025 11:10 AM

    It's much easier to use ODBC.

    1. Install the IBM i Access Client Solutions "Application Package" for your platform.
      • If Python is executing on IBM i itself to access the IBM i, it's yum install unixodbc ibm-iaccess
    2. Create a Python virtual environment.
    3. Activate that virtual environment.
    4. pip install pyodbc
    5. Create a Data Set Name (DSN) for your IBM i
      • This is ODBC and not specific to IBM i ... google ODBC DSN for your platform
      • On IBM i itself, you do not need to create a data source name, just use "DSN=*LOCAL" in your connection string.

    After that, this simple example should work:

    import pyodbc

    cn = pyodbc.connect("DSN=dsn_for_your_system")
    cursor = cn.cursor()
    cursor.tables()
    rows = cursor.fetchall()
    for row in rows:
      print(row.table_name)
    cursor.close()

    .. which will print out all the tables in your library list.



    ------------------------------
    Jack Woehr
    Senior Consultant
    Seiden Group LLC
    Beulah CO
    3038478442
    ------------------------------



  • 6.  RE: Getting started with Python on the IBM Power system

    Posted Fri March 07, 2025 06:17 AM

    Hi Michael,
    I have provided detailed steps in my blog to help you read a DB2 table using Python. It covers everything from installing dependencies and setting up the connection string to executing queries using pyodbc to connect to IBM i DB2.
    https://community.ibm.com/community/user/power/blogs/gaurav-khanna/2025/03/04/connecting-ibm-i-as400-db2-remotely-via-python-usi

    Hope it helps you!



    ------------------------------
    Gaurav Khanna
    ------------------------------



  • 7.  RE: Getting started with Python on the IBM Power system

    Posted Fri March 07, 2025 08:25 PM

    Thank you everyone for all these great resources.  I will definitely check out all this information.

    -Mike



    ------------------------------
    Michael Soucy
    ------------------------------