Power of Python Integrated with SAP HANA

Python is a high-level, object-oriented programming language for the web.
Python is easy to write, easy to read and easy to understand.
SAP HANA works quite well with Python.
This article gives a basic idea of how to use Python on SAP HANA.
hana sap hana online training updates with Python

Note: Even if you are not familiar with Python, do not worry. We are all and cover everything in detail for you.

Python API:

There are several APIs available for free Python for SAP HANA. In this article, we are one of the easiest, use the DB-API.
dbapi API is Python DB-API 2.0.

Configure Python API in SAP HANA:

1 Navigate to the location where you installed the client HANA and copy these three files.,

sap hana online training updates with python power integration
By default it is installed in C: Program Files folder Filessaphdbclienthdbcli.
2 Navigate to the folder under the folder HDBClient Python and copy all three files in the lib.
By default, the path C: Program FilessaphdbclientPythonLib
3 Copy pyhdbcli.pdb, pyhdbcli.pyd files from hdbclient.
By default, this location is "Program Filessaphdbclient C" is
4 On the same folder pythonlib and add these 2 files.
This is all.Configuration done! ...

Connect to SAP HANA and Run SQL Queries using Python:

1.   Write below code in a notepad and save with .py extension. 
import dbapi
## Replace SCHEMA1 with your schema

# assume HANA host id is abcd1234 and instance no is 00. user id is USER1 and password is Password1
conn = dbapi.connect('abcd1234', 30015, 'USER1', 'Password1')

#Check if database connection was successful or not
print conn.isconnected()

# create a table
cursor = conn.cursor()
stmnt = 'Create column table SCHEMA1.table1 (ID integer, name varchar(10))'
print 'table created'

# insert some data into table
stmnt = 'insert into SCHEMA1.table1 values (?, ?)'
cursor.execute(stmnt, (1,'A'))
cursor.execute(stmnt, (2,'B'))
print '2 records inserted into table'

# fetch table data
stmnt = 'select * from SCHEMA1.table1'
result = cursor.fetchall()
print result

2. Provide system data HANA and recording information of the file.
3. Make sure that you change the name of the schema with your schema.
4. Now save the file in the folder hdbclientPython.
The default location of Python folder "C: Program FilessaphdbclientPython"
5. Open ask. Switch to the Python path, and run the command

No comments :

Post a Comment