Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

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.

But what about a connection to gateway using OData?

There are documents about connecting to gateway for PHP, 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:

  1. 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.
  2. 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!

Small update: I have been playing around with django at JavaScript Jobs and as a hobby project, I would like to try create odata plugin for django. If is someone willing to help me let me know.

1 Comment