Discover how Metaflow assists you, with diagrams and visualization from production to deployment. For more information, see the the Metaflow documentation.
Step 1Set up your system, and Python
โ
CAUTIONFor Windows Users: Please use an alternate option tab to set up. Otherwise the Metaflow library could cause issues in installation.
Create and activate a virtual Python environment using the following snippet. Note, tutorial_metaflow is the name of your environment. The Python virtual environment helps you install Python packages inside a sandbox-like environment. You use the environment to maintain required versions of the packages for your project.
Check which Python is used by your virtual environment. You can see the path of the Python executable in your virtual environment.
Shell
which python
Create a file named Dockerfile with following contents. This file stores instructions for Docker to build an image. You will run this Docker image in your local system to create a sandbox environment similar to a Virtual Machine.
Dockerfile
FROM python# FROM python:3.9.13 # (optional) specific versionRUN apt updateRUN apt install -y docker.io docker
Build the Docker image and run the Docker environment.
INFORMATION Only for users comfortable at self debugging code. If you are using Linux or MacOS then you may also try executing the lines from the Dockerfile without the FROM & RUN commands to set up in you local machine rather than in Docker’s sandbox container.
Create file Dockerfile with following contents. The base Docker image is pytorch v1.10 which is required for the dectectron2 package of python.
Edit the following snippet and the paste in the config.json file, created above. Replace <YOUR_S3_BUCKET_NAME> with AWS S3 bucket ID that you want Metaflow to use to store files.
Create a credentials file for your AWS S3 Object Store. The file is used by the Metaflow package access your AWS S3 store.
Shell
mkdir -p $HOME/.aws
touch $HOME/.aws/credentials
Edit the following snippet and paste it in your credentials file. Replace <YOUR_S3_ACCESS...> with your AWS S3 credentials, do not enclose your credentials within quotes("").
INFORMATION the Metaflow library for SAP AI Core uses AWS, however you may skip the installation of AWS CLI.
Step 6Metaflow HelloWorld
+
Create a file hellometaflow.py with following contents.
Python
# You should divide the contents of the steps of the pipeline file into different python modules.# However the contents within each step may have snippets imported from separate python packages/modules.frommetaflowimportFlowSpec,stepclassHelloFlow(FlowSpec):"""
A flow where Metaflow prints 'Hi'.
Run this flow to validate that Metaflow is installed correctly.
"""@stepdefstart(self):"""
This is the 'start' step. All flows must have a step named 'start' that
is the first step in the flow.
"""print("HelloFlow is starting.")self.next(self.hello)@stepdefhello(self):"""
A step for metaflow to introduce itself.
"""print("Metaflow says: Hi!")self.next(self.end)@stepdefend(self):"""
This is the 'end' step. All flows must have an 'end' step, which is the
last step in the flow.
"""print("HelloFlow is all done.")if__name__=="__main__":HelloFlow()
Inspect the steps of the Metaflow pipeline hellometaflow.py using following snippet.
Shell
python hellometaflow.py show
Run this snippet locally.
Shell
python hellometaflow.py run
metaflow
Step 8Save set up environment
+
To deactivate Python virtual environment, use the following command.
Shell
deactivate
CAUTION: These steps are only applicable if you used the Docker environment in the step 1.
Docker containers are ephemeral, meaning that the installation you did inside will lost upon closing. To save the changes, first locate your container ID using the following snippet on your local system (not inside the Docker container).
Shell
docker ps
Use container resulting container ID to save the changes, including files, installations and commands, in the form of Docker images:
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 8
1. Set up your system, and Python2. Set environment variables3. Install Metaflow package4. Configure Metaflow5. Configure AWS6. Metaflow HelloWorld7. Run Metaflow pipeline locally8. Save set up environment
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.