Intro
Python is my favorite programming language, the reason for this blog post is just my curiosity.
There are few ways how to make python work with SAP.
- PyRFC - Python / ABAP Stack
- ODBC connection to HANA database SAP HANA and Python? Yes Sir!
But what about a connection to gateway using OData?
There are documents about connecting to gateway forPHP, Java Script, Flex, .NET, Objective C in SAP NetWeaver Gateway Developer Center. But where is Python?
OData library for python
I started to look for an odata library and found two reasonable options:
- OData-py is "OData provider for Google App Engine Datastore". Unfortunately, it can be probably used only in google app engine, has several limitations, and is not maintained since 2011.
- Pyslet is "Python for Standards in Learning Education & Training". It includes module which implements OData client and also server. Let's see what it can offer.
Running Pyslet on web.py
Web.py is a small python framework for creating web applications. Integration was simple - install pyslet, import a module and you are can start consuming an OData service. I created small hello world application that fetches product list and displays product names.
Header:
from pyslet.odata2.client import Client
Handling class:
class index: def GET(self): c=Client("http://services.odata.org/V2/Northwind/Northwind.svc/") products=c.feeds['Products'].OpenCollection() productNames = [] for k,p in products.iteritems(): productNames.append(p['ProductName'].value) web.header('Content-Type', 'text/html') return render_template('index.html', products = productNames)
Template:
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <title>Python + ODATA</title> </head> <body> <table border="1"> <tr><td><strong>Name</strong></td></tr> {% for name in products %} <tr><td>{{name}}</td></tr> {% endfor %} </table> </body></html>
And the result:
Conclusion
I used information from author's blog - http://swl10.blogspot.com/. More useful and detail information can be found there.
This was just a simple experiment. Author claims that the module does not work with HTTPS OData service, so basically it cannot be used in real environment.
Next challenge? HTTPS source and more sophisticated application!
Looking for you feedback.