Python WebApi with IBM i DB
This demo show how to set up an web service server (WebAPI) based on python
This WebAPI can run on Linux, Windows and IBM i.
You only need an ODBC driver on your machine.
So, you can develop the WebAPI on your local computer.
When you have finished your work, you can deploy it on your IBM i without changing your code (if you have a clean environment 👀 ).
-
Requirements
-
Install IBM i ODBC Driver
-
Download the ACS PASE App (IBMiAccess_v1r1_PASE_AP.zip)
-
Extract it
-
Go into the ppc64 directory
There you should find a file like
ibm-iaccess-1.1.0.15-0.ibmi7.2.ppc64.rpm
-
Install this ODBC Driver file via YUM
yum install unixODBC ibm-iaccess-1.1.0.15-0.ibmi7.2.ppc64.rpm
You can check your ODBC settings using the
odbcinst
command-bash-5.1$ odbcinst -j unixODBC 2.3.9 DRIVERS............: /QOpenSys/etc/odbcinst.ini SYSTEM DATA SOURCES: /QOpenSys/etc/odbc.ini FILE DATA SOURCES..: /QOpenSys/etc/ODBCDataSources USER DATA SOURCES..: /home/PROUZA/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8
-
-
Install Python ODBC driver
-bash-5.1$ yum install python39 python39-devel python39-pyodbc python39-wheel python39-six python39-setuptools python39-pandas
-
-
Go into your directory
This is the directory where your
requirements.txt
file is stored.-bash-5.1$ cd python-webapi/webapi
-
Create a virtual environment
-bash-5.1$ python -m venv --system-site-packages ./venv
-
Activate your virtual environment
-bash-5.1$ source venv/bin/activate
-
Upgrade your PIP first (recommended)
(venv) -bash-5.1$ pip install --upgrade pip
-
Install Python required packages
(venv) -bash-5.1$ pip install -r requirements.txt
-
Run the WebService
(venv) -bash-5.1$ python webapi.py
-
Now you can test via HTTP in your browser
You also can see logs in log/webapi.log
By default the Flask DevelopmentConfig will be taken
app.config.from_object(flask_config.DevelopmentConfig())
In this configuration the HOST
variable is set to 0.0.0.0
which means you can also access it from outside the server.
This is defined, that you can run tests from your local machine.
For security reason on production system it's highly recommended to use an http proxy like Apache or NGinx to reroute the request internal to your python service.
Because of this on production system HOST
variable is set to 127.0.0.1
.