-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add blueprint on python command that can take an input using an… (
#20) * feat: add blueprint on python command that can take an input using an environment variable * Update python-input-as-env-variable.yaml --------- Co-authored-by: Will Russell <[email protected]>
- Loading branch information
1 parent
6b6f00c
commit 082aca9
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
id: python-input-as-env-variable | ||
namespace: company.team | ||
|
||
inputs: | ||
- id: uri | ||
type: URI | ||
defaults: https://www.google.com/ | ||
|
||
tasks: | ||
- id: code | ||
type: io.kestra.plugin.scripts.python.Commands | ||
namespaceFiles: | ||
enabled: true | ||
taskRunner: | ||
type: io.kestra.plugin.scripts.runner.docker.Docker | ||
containerImage: ghcr.io/kestra-io/pydata:latest | ||
commands: | ||
- python main.py | ||
env: | ||
URI: "{{ inputs.uri }}" | ||
|
||
extend: | ||
title: Run a Python command that can takes an input using an environment variable | ||
description: >- | ||
This workflow passes the input as an environment variable to the Python code. | ||
The `code` task, which is the python `Commands` task, has the `env` property | ||
that sets the environment variables. The value of these environment variables | ||
can be based on the inputs. The `main.py` file that gets executed using the | ||
python commands task can then use these environment variables which contain | ||
the inputs. | ||
For this workflow, the `main.py` file will have the following code: | ||
```python | ||
import requests | ||
import os | ||
# Perform the GET request | ||
response = requests.get(os.environ['URI']) | ||
# Check if the request was successful | ||
if response.status_code == 200: | ||
# Print the content of the page | ||
print(response.text) | ||
else: | ||
print(f"Failed to retrieve the webpage. Status code: {response.status_code}") | ||
``` | ||
Notice how the python code uses the `URI` environment variable. | ||
tags: | ||
- Python | ||
- Inputs | ||
ee: false | ||
demo: true | ||
meta_description: This flow runs the python file that takes the input using an environment variable. |