
I am writing this blog to describe the configuration procedures required for Python development in SAP Business Application Studio. This process is divided into the following four key steps:
As considerable time has elapsed since the setup of my environment, I am unable to provide detailed pre-requisites.
On SAP BAS screen, click on "Create Dev Space" button.
With the below input, click on "Create Dev Space" button.
Click on Dev Space name after the instance starts.
select "Creates empty project" from command palette and enter project name after the selection.
The project I'm going to deploy is very simple, so I don't create MTA app.
From command palette, set default python runtime. The default runtime is "/home/user/.asdf-inst/shims/python".
See "Runtime Version Management" for further detail.
* This step might be unnecessary, since I choose the same path when creating a python virtual environment.
After that, create python environment.
select ".venv". I just prefer .venv to .conda for python development.
select "~/.asdf-inst/shims/python3".
Though it is not mandatory step, I usually use jupyter for development.
Firstly, create a new jupyter notebook from command palette.
Click on "Select Kernel" and choose "Python Environments"
select ".venv".
When I run jupyter cells, jupyter is automatically installed.
Implement simple python rest api app based on an article "Create simple Flask REST API using Cloud Foundry".
Install Flask using pip.
Then terminal runs and it automatically activate configured python.
install Flask using pip.
(.venv) user: python-test $ pip install Flask
Collecting Flask
Downloading flask-3.0.3-py3-none-any.whl.metadata (3.2 kB)
Collecting Werkzeug>=3.0.0 (from Flask)
Downloading werkzeug-3.0.3-py3-none-any.whl.metadata (3.7 kB)
Requirement already satisfied: Jinja2>=3.1.2 in ./.venv/lib/python3.11/site-packages (from Flask) (3.1.4)
Collecting itsdangerous>=2.1.2 (from Flask)
Downloading itsdangerous-2.2.0-py3-none-any.whl.metadata (1.9 kB)
Collecting click>=8.1.3 (from Flask)
Downloading click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting blinker>=1.6.2 (from Flask)
Downloading blinker-1.8.2-py3-none-any.whl.metadata (1.6 kB)
Requirement already satisfied: MarkupSafe>=2.0 in ./.venv/lib/python3.11/site-packages (from Jinja2>=3.1.2->Flask) (2.1.5)
Downloading flask-3.0.3-py3-none-any.whl (101 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 101.7/101.7 kB 7.2 MB/s eta 0:00:00
Downloading blinker-1.8.2-py3-none-any.whl (9.5 kB)
Downloading click-8.1.7-py3-none-any.whl (97 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 8.4 MB/s eta 0:00:00
Downloading itsdangerous-2.2.0-py3-none-any.whl (16 kB)
Downloading werkzeug-3.0.3-py3-none-any.whl (227 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 227.3/227.3 kB 13.8 MB/s eta 0:00:00
Installing collected packages: Werkzeug, itsdangerous, click, blinker, Flask
Successfully installed Flask-3.0.3 Werkzeug-3.0.3 blinker-1.8.2 click-8.1.7 itsdangerous-2.2.0
create "app.py".
from flask import Flask
import os
app = Flask(__name__)
# Port number is required to fetch from env variable
# http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#PORT
cf_port = os.getenv("PORT")
# Only get method by default
@app.route('/')
def hello():
return 'Hello World'
if __name__ == '__main__':
if cf_port is None:
app.run(host='0.0.0.0', port=5000, debug=True)
else:
app.run(host='0.0.0.0', port=int(cf_port), debug=True)
In terminal, run "python app.py" and click on "Open in a New Tab" button.
"Hello World" is displayed in a new tab.
Create some files for deployment and deploy to BTP Cloud Foundry.
manifest.yml for BTP Deployment. Probably this is the minimum specs to run the app.
---
applications:
- memory: 128MB
disk_quota: 512MB
random-route: true
Target python application.
web: python app.py
Target python version.
python-3.11.X
Necessary python packages.
Flask
".venv" is unnecessary to run cf app, so list up the directory.
.venv
Deploy the app to cloud foundry. My login target is eu10.
cf login -a https://api.cf.eu10.hana.ondemand.com
cf push <app name>
As an alternative way for login, you can use command palette.
Deployed URL is shown on the terminal, so access the URL via browser.
If you don't need the app on cloud foundry, just delete the app.
cf delete <app name>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
29 | |
26 | |
23 | |
20 | |
19 | |
15 | |
15 | |
13 | |
8 | |
8 |