Skip to Content

Python?

The guiding principles for Python‘s design are summarized in PEP 20 – The Zen of Python. My personal top three are…

“Now is better than never.”

Yes, now is better than never and we now announce that Python is among the supported runtimes in SAP Cloud Platform!

“Complex is better than complicated.”

Sometimes it may seem complex to learn a new language. Still, it’s usually better to get into such a complex situation and use the right tool instead of ending up in a complicated situation where you try to address different challenges with only one tool.

“If the implementation is easy to explain, it may be a good idea.”

Seems like an important goal of Python’s community is keeping the language fun and easy to use. For the fun part, one can tell already by the name which is a tribute to the British comedy group Monthy Python. As for the easy, I’m not an expert here, rather a newbie and I found a lot of Python learning materials for different levels of expertise.

I guess Python is a good idea looking at it’s growing adoption. As of September 2018, Python is the third most popular programming language according to TIOBE Programming Community Index. Maybe it’s because it’s a suitable choice of technology for multiple cases: web development having multiple frameworks and supporting different Internet protocols, scientific and numeric computing with a set of math and data analysis libraries, and of course it’s a pretty famous choice when it comes to AI: be it general AI, machine learning, natural language, and text processing or neural networks.

SAP Cloud Platform & Python?

In SAP Cloud Platform Cloud Foundry environment you can deploy Python applications using the community Python buildpack.

Python is one of those languages that are designed as highly extensible: there are more than 130,000 open-source packages that one can use, take a look at PyPi (Python Package Index). We have also SAP provided Python packages for e.g. security integration, libraries providing means to emit structured application logs and instrument web apps to collect request metrics, SAP HANA Database Client, etc. Wondering how to use the SAP provided packages?

 

  • In the search bar type XS PYTHON. Download the XS_PYTHON archive – it contains the SAP Python Packages. Extract the zip in a directory e.g. sap_dependencies.

  • Our recommendation is to deploy applications that are self-contained. This means they carry all their dependencies. This way the staging process does not require any network access and your builds are completely reproducible. Python buildpack provides a mechanism for that. Applications can vendor their dependencies by storing them in a “vendor” folder in their root directory. You need pip manager installed locally, check: https://packaging.python.org/tutorials/installing-packages/

Note: There are two important aspects to have in mind when you vendor application dependencies – the platform where your application will run (the operating system) and Python version.

  • To vendor your application dependencies, open a command prompt, go to your python application root folder and execute the following command:
$ cd YOUR-APP-DIR
$ pip download -d vendor -r requirements.txt –-find-links sap_dependencies

Option -r points to the requirements file which will be used to determine dependencies; -d tells pip to download the required dependencies in a folder called vendor in the root of your application; –find-links parameter points to the directory where you unzipped the archive containing SAP Python packages.

  • After a successful execution of the command your python application root folder should look something like this:
|--simple-python-app
   |--hello.py
   |--requirements.txt
   |--manifest.yml
   |--LICENSE.txt
   `--vendor
      |--Flask-0.12.2-py2.py3-none-any.whl
      `--hdbcli-2.3.14-cp27-cp27m-macosx_10_6_x86_64.whl
  • And that’s it — you’re good to go.

Hungry for more?

  • For more details about the contents of each SAP provided Python package as well as specific configuration tips, see the README file in the corresponding package.
  • Want to learn more about developing and running Python applications on SAP Cloud Platform? Check out python documentation on help.sap.com.
  • Stay tuned for more PyBlogs …

 

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Jorge Laranjo

    Examples are available on the DESCRIPTION.rst file on the module itself but in fairness the example does not work as in returns

    Validation error: Error from JwtEvalToken. Invalid alg in JWT header

    which is not a great example 😀

    Got it working using RS256 and changing the example on DESCRIPTION.rst to cast jwtver.getPayload() to str otherwise returns bytes

     

    Is there a GitHubrepo for the library?

    (0) 
    1. Ina Ivanova Post author

      Thanks for the feedback! Unfortunately, the library is not an open source project and the GitHub repo is private so you cannot contribute directly there. I contacted the dev team for this broken sample, so looking forward to the fixed version 🙂

      (0) 

Leave a Reply