It's been a while since I wrote my last Python blog...July 15, 2011 Tasting the mix of Python and SAP - Volume 3...almost a year...so I thought it was a good thing to get back into action...but...what else could I wrote about? I started to check my options and of course I quickly thought on SAP HANA. After all, I have my own server running on Amazon Web Services so it sound like a good plan.
At first I wanted to use SAP HANA as an ODBC connection like I did with #R in the early days...but then I heard that Python was actually embedded on the SAP HANA Client installation, so it only took a little checking, and some SAP internal forum to discover that, using Python and SAP HANA is easier that I could ever imagine...
First, you need to go where your SAP HANA Client is installed, and then copy the 3 files from the hdbcli folder...
Then, go to the Python folder and copy these files into the Lib folder...
Do the same with this 2 files in the hdbclient folder, copy them and paste them into the Python/Lib folder...
With that, we're ready to go...download any Python IDE and assign Python.exe (from the Python folder on hdbclient) as the Python executable.
If this little program prints "TRUE" on the screen, it means that the connection is done.
Go to http://pypi.python.org/pypi/setuptools#windows and copy the ez_setup.py file into your Python folder. Executed in the command line like Python ez_setup.py to install the tools and then add the directory "full path/Python/Scripts" to your path variable in the Windows System variables...
With that, you can directly call Easy_Install...that we're going to need in order to install Bottle, a Python Web Micro framework.
In the command prompt write:
easy_install -U bottle
With that, we're ready to start :smile:
from bottle import get, post, request, run, redirect, route
output += "<H1>%s records in %s seconds</H1></DIV>" % (counter, time_taken)
We when run this code, the Bottle Web Server is going to start, so we need to go to http://localhost:8080/login to start the application.
We need of course to log in :wink:
We can choose a Carrier and the City From for our query (Of course, both Dropdown list are filled with data coming from SAP HANA).
Let's show the query in a nice table...
It took a little bit more than 3 seconds to fetch data from SAP HANA and the to print it on Python. Almost 3K records in 3 seconds? That's fast...specially when we considered that Python is not exactly the fastest tool in the market :smile:
I hope you like this blog, as I really enjoyed working on it. It's always a great experience to use Python, SAP HANA or any other programming language to develop something new