0% found this document useful (0 votes)
3 views54 pages

Python in IBM I - Getting Started

The document outlines a technical workshop on getting started with Python on IBM i, detailing installation steps, modern tools, and community packages. It introduces the 5733OPS Open Source for IBM i license program and highlights Python's capabilities, including a native DB2 connector and various built-in services. The workshop agenda includes practical examples and usage of Python in web development and database management.

Uploaded by

nryn3108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views54 pages

Python in IBM I - Getting Started

The document outlines a technical workshop on getting started with Python on IBM i, detailing installation steps, modern tools, and community packages. It introduces the 5733OPS Open Source for IBM i license program and highlights Python's capabilities, including a native DB2 connector and various built-in services. The workshop agenda includes practical examples and usage of Python in web development and database management.

Uploaded by

nryn3108
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

IBM i テクニカル・ワークショップ 2016

Getting Started with Python on IBM i

Jesse R. Gorzinski, MBA


[email protected]
IBM i Emerging Solutions
IBM Corporation

© Copyright IBM Corporation 2016


IBM i テクニカル・ワークショップ 2016

Agenda

• Introduction
• Install Python on i
• Use modern tools
• Explore what you get
• Install community packages
• Hello, world!
• Let's go to the web!

© Copyright IBM Corporation 2016


1
IBM i テクニカル・ワークショップ 2016
Open Source for IBM i

• New LPO – 5733OPS Open Source for IBM i


• New license program option
• Designed for Open Source offerings on IBM i
• Provides a safe way for Open Source to be delivered on IBM i

© Copyright IBM Corporation 2016


2
IBM i テクニカル・ワークショップ 2016

Python success stories!

• https://www.python.org/about/success/

• 41 real-life success stories across multiple domains

© Copyright IBM Corporation 2016


3
IBM i テクニカル・ワークショップ 2016

Install Python on i

© Copyright IBM Corporation 2016


4
IBM i テクニカル・ワークショップ 2016

5733-OPS: a bit unconventional?

• 5733-OPS has 15 options available NOW!

• The options themselves are placeholders

• Function will be delivered via PTF

© Copyright IBM Corporation 2016


5
IBM i テクニカル・ワークショップ 2016

Installing Python on i

1. Install XMLSERVICE
http://yips.idevcloud.com/wiki/index.php/XMLService/XMLSERVICEInstall

2. Install 5733OPS Option 2

3. Install latest SC1 PTF's


https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/
wiki/W1c12c273752d_4cb8_b000_8375ec43426d/page/5733-
SC1%20PTFs

4. Install new-function PTF's


SI59051  runtime
SI58191
SI58195
SI58192
5. SI58193
(or latest superceding PTF's).

6. Verify the install by running 'python3 --version' from a terminal

© Copyright IBM Corporation 2016


6
IBM i テクニカル・ワークショップ 2016

Installing shipped add-ons (install PTF first)

DB2 connector (SI58191):


easy_install3 /QOpenSys/QIBM/ProdData/OPS/Python-pkgs/ibm_db/ibm_db-*.egg

Toolkit for IBM i (SI58195):


easy_install3 /QOpenSys/QIBM/ProdData/OPS/Python-pkgs/itoolkit/itoolkit-*.egg

FastCGI gateway support (SI58192):


easy_install3 /QOpenSys/QIBM/ProdData/OPS/Python-pkgs/flipflop/flipflop-*.egg

lightweight web framework (SI58193):


easy_install3 /QOpenSys/QIBM/ProdData/OPS/Python-pkgs/bottle/bottle-*.egg

© Copyright IBM Corporation 2016


7
IBM i テクニカル・ワークショップ 2016

Use modern tools

© Copyright IBM Corporation 2016


8
IBM i テクニカル・ワークショップ 2016

Modern terminal

© Copyright IBM Corporation 2016


9
IBM i テクニカル・ワークショップ 2016

Modern terminal

• Use SSH!
• A good way from Windows (not the only way):
1. Install cygwin (make sure that SSH is part of install)
2. Programs  Cygwin  Cygwin64 Terminal
3. ssh -Y <userid>@<hostname>
(optional) 'exec bash' for a more friendly shell (in Jesse's opinion)

Can also make bash the default by following these steps:


http://www-01.ibm.com/support/docview.wss?uid=nas8N1011555

© Copyright IBM Corporation 2016


10
IBM i テクニカル・ワークショップ 2016

Modern terminal

© Copyright IBM Corporation 2016


11
IBM i テクニカル・ワークショップ 2016

Modern text editor

© Copyright IBM Corporation 2016


12
IBM i テクニカル・ワークショップ 2016

Modern text editor

Many options
• Can map a drive, use Windows editor of choice (for example)
• Or, use nedit with X11 forwarding (topic for another day

Jesse's preferred method: Eclipse with Remote System Explorer plugin


• Easily found and installed through Eclipse Marketplace
(Help  Eclipse Marketplace…)
• Then, go to "Window  Open Perspective"

© Copyright IBM Corporation 2016


13
IBM i テクニカル・ワークショップ 2016

Remote System Explorer

© Copyright IBM Corporation 2016


14
IBM i テクニカル・ワークショップ 2016

Remote System Explorer

© Copyright IBM Corporation 2016


15
IBM i テクニカル・ワークショップ 2016

Explore what you get

© Copyright IBM Corporation 2016


16
IBM i テクニカル・ワークショップ 2016

Base Python runtime

python3 / python3.4
This is the main Python executable.
pip3 / pip3.4
Preferred package installer.
2to3 / 2to3-3.4
Transforms Python 2.x code to Python 3.x
pydoc3 / pydoc3.4
Documentation generator
pyvenv / pyvenv-3.4
Provides support for lightweight virtual environments.
easy_install3 / easy_install-3.4
Lets you build, install, and manage Python packages. This command is
used for installing shipped add-ons.

© Copyright IBM Corporation 2016


17
IBM i テクニカル・ワークショップ 2016

Native DB2 connector

• Provided by the ibm_db open source project

• Incredibly robust. Can do many DB2 functions!

• Conforms to Python Database API Specification v2.0

• Complete documentation can be found here:


https://code.google.com/p/ibm-db/wiki/APIs

© Copyright IBM Corporation 2016


18
IBM i テクニカル・ワークショップ 2016
Simple select statement

QSQSRVR DB2 BCI … task 1, then task 2

© Copyright IBM Corporation 2016


19
IBM i テクニカル・ワークショップ 2016

Creating HTML table from a select (we'll see a screenshot later)

© Copyright IBM Corporation 2016


20
IBM i テクニカル・ワークショップ 2016

Built in DB2 Services – Use SQL to get info from the system!

PTF Services
Storage Services
QSYS2.PTF_INFO
QSYS2.USER_STORAGE
QSYS2.GROUP_PTF_INFO
QSYS2.SYSDISKSTAT
Security Services
QSYS2.USER_INFO QSYS2.SYSTMPSTG

QSYS2.FUNCTION_INFO Object Services

QSYS2.OBJECT_STATISTICS()
QSYS2.FUNCTION_USAGE

QSYS2.GROUP_PROFILE_ENTRIES
System Health Services
QSYS2.SQL_CHECK_AUTHORITY()
QSYS2.SYSLIMTBL
QSYS2.SET_COLUMN_ATTRIBUTE()
QSYS2.SYSLIMITS
Work Management Services

QSYS2.SYSTEM_VALUE_INFO Journal Services

QSYS2.GET_JOB_INFO() QSYS2.DISPLAY_JOURNAL()

TCP/IP Services Application Services

SYSIBMADM.ENV_SYS_INFO
QSYS2.QCMDEXC()

QSYS2.TCPIP_INFO

© Copyright IBM Corporation 2016


21
IBM i テクニカル・ワークショップ 2016

Built in DB2 Services – Examples

SELECT * FROM QSYS2.USER_INFO


WHERE SIGN_ON_ATTEMPTS_NOT_VALID > 0

SELECT
ASP_NUMBER,UNITNBR,PERCENT_USED
FROM QSYS2.SYSDISKSTAT

© Copyright IBM Corporation 2016


22
IBM i テクニカル・ワークショップ 2016

Toolkit for IBM i

• Three different ways to use it:


• Direct calls (like CLP)
• REST calls (local/remote)
• DB2 calls (local/remote)

http://youngiprofessionals.com/wiki/index.php/XMLSERVICE/Python

© Copyright IBM Corporation 2016


23
Toolkit example: rtvjoba IBM i テクニカル・ワークショップ 2016

© Copyright IBM Corporation 2016


24
IBM i テクニカル・ワークショップ 2016
Toolkit example: DB2

© Copyright IBM Corporation 2016


25
IBM i テクニカル・ワークショップ 2016
Toolkit example: DB2

© Copyright IBM Corporation 2016


26
IBM i テクニカル・ワークショップ 2016
Toolkit example: *PGM

© Copyright IBM Corporation 2016


27
IBM i テクニカル・ワークショップ 2016
Toolkit example: *SRVPGM

© Copyright IBM Corporation 2016


28
System API IBM i テクニカル・ワークショップ 2016

# Retrieve Hardware Resource List (QGYRHRL, QgyRtvHdwRscList) API


# Service Program: QGYRHR
# Default Public Authority: *USE
# Threadsafe: No
# Required Parameter Group:
# Output Char(*)..............Receiver variable (RHRL0100, RHRL0110)
# Input Binary(4).............Length of receiver variable
# Input Char(8)...............Format name
# Input Binary(4).............Resource category
# I/O Char(*).................Error code
# RHRL0100 Format
# BINARY(4)...................Bytes returned
# BINARY(4)...................Bytes available
# BINARY(4)...................Number of resources returned
# BINARY(4)...................Length of resource entry
# CHAR(*).....................Resource entries
# These fields repeat for each resource.
# BINARY(4)...................Resource category
# BINARY(4)...................Family level
# BINARY(4)...................Line type
# CHAR(10)....................Resource name
# CHAR(4).....................Type number
# CHAR(3).....................Model number
# CHAR(1).....................Status
# CHAR(8).....................System to which adapter is connected
# CHAR(12)....................Adapter address
# CHAR(50)....................Description
# CHAR(24)....................Resource (liar, liar, pants on fire, binary)

© Copyright IBM Corporation 2016


29
System API (input) IBM i テクニカル・ワークショップ 2016

© Copyright IBM Corporation 2016


30
System API (report)
IBM i テクニカル・ワークショップ 2016

© Copyright IBM Corporation 2016


31
System API (run) IBM i テクニカル・ワークショップ 2016

bash-4.3$ python isrvpgm_qgyrhrl.py


+++ success QGYRHR QgyRtvHdwRscList
Length of receiver variable......123892
Format name......................RHRL0100
Resource category................3
RHRL0100_t:
Bytes returned.................388
Bytes available................388
Number of resources returned...3
Length of resource entry.......124
--------------------------------------------------------
Resource category............3
Family level.................1
Line type....................-1
Resource name................CMB02
Type number..................268C
Model number.................001
Status.......................1
System adapter connected.....*NONE
Adapter address..............*NONE
Description..................Comm Processor
Resource kind................0000000000000001000000000000000740
--------------------------------------------------------
Resource category............3
Family level.................2
Line type....................-1
Resource name................CTL01
Type number..................6A59
Model number.................002
Status.......................1
System adapter connected.....*NONE
Adapter address..............*NONE
Description..................Virtual Controller
Resource kind................000000000000000200000000000000010000080008
--------------------------------------------------------
Resource category............3
Family level.................3
Line type....................-1
Resource name................DSP001
: 2016
© Copyright IBM Corporation
… so on ...
32
IBM i テクニカル・ワークショップ 2016

FastCGI gateway

• We ship a fastCGI gateway, built from the flipflop open source project

© Copyright IBM Corporation 2016


33
IBM i テクニカル・ワークショップ 2016

Lightweight web framework

• We ship a slightly-modified version of the open-source bottle.py

• Lots of reference at http://bottlepy.org

• We'll see a small example later

© Copyright IBM Corporation 2016


34
IBM i テクニカル・ワークショップ 2016

Install community packages

© Copyright IBM Corporation 2016


35
IBM i テクニカル・ワークショップ 2016

Using the pip3 command (install from Internet)

Usage:
pip3 <command> [options]

Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
zip DEPRECATED. Zip individual packages.
unzip DEPRECATED. Unzip individual packages.
bundle DEPRECATED. Create pybundles.
help Show help for commands.

General Options:
-h, --help Show help.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log-file <path> Path to a verbose non-appending log, that only logs failures. This log is active by
default at /home/JGORZINS/.pip/pip.log.
--log <path> Path to a verbose appending log. This log is inactive by default.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
--cert <path> Path to alternate CA bundle.

© Copyright IBM Corporation 2016


36
IBM i テクニカル・ワークショップ 2016

Installing xlsxwriter

© Copyright IBM Corporation 2016


37
IBM i テクニカル・ワークショップ 2016

xlsxwriter example

© Copyright IBM Corporation 2016


38
IBM i テクニカル・ワークショップ 2016

xlsxwriter example

© Copyright IBM Corporation 2016


39
IBM i テクニカル・ワークショップ 2016

Hello, world!

© Copyright IBM Corporation 2016


40
IBM i テクニカル・ワークショップ 2016

Python interactive

• Interactive:

• Script:

© Copyright IBM Corporation 2016


41
IBM i テクニカル・ワークショップ 2016

Let's go to the web!

© Copyright IBM Corporation 2016


42
IBM i テクニカル・ワークショップ 2016

fastCGI (already saw this)

© Copyright IBM Corporation 2016


43
IBM i テクニカル・ワークショップ 2016

http.server (included with Python)

© Copyright IBM Corporation 2016


44
IBM i テクニカル・ワークショップ 2016

bottle.py (shipped add-on)

https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/
wiki/IBM%20i%20Technology%20Updates/page/Sample%20web%20app
lication%20with%20Python

© Copyright IBM Corporation 2016


45
IBM i テクニカル・ワークショップ 2016

bottle.py

• Quick, easy-to-use, lightweight web framework!


• Lets you serve up static files, images, dynamically-generate code, and
much more

© Copyright IBM Corporation 2016


46
IBM i テクニカル・ワークショップ 2016

bottle (shipped add-on)

https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/
wiki/IBM%20i%20Technology%20Updates/page/Sample%20web%20app
lication%20with%20Python

© Copyright IBM Corporation 2016


47
IBM i テクニカル・ワークショップ 2016

© Copyright IBM Corporation 2016


48
IBM i テクニカル・ワークショップ 2016

code for DB2 query function

© Copyright IBM Corporation 2016


49
IBM i テクニカル・ワークショップ 2016

© Copyright IBM Corporation 2016


50
IBM i テクニカル・ワークショップ 2016

Code for CL command function

© Copyright IBM Corporation 2016


51
IBM i テクニカル・ワークショップ 2016

• "The web framework for perfectionists with deadlines"

• Very powerful. Has MVC frameworks built-in. Requires a database


connection for keeping relationship mappings, structural data, etc

• On IBM i, one can use MySQL via Zend Dbi


https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM%20i%
20Technology%20Updates/page/First%20Django%20web%20application

© Copyright IBM Corporation 2016


52
IBM i テクニカル・ワークショップ 2016
Django example

http://lightbird.net/dbe2/questionnaire.html#questionnaire-model

© Copyright IBM Corporation 2016


53

You might also like