-
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.
Merge pull request #16 from shrutimantri/inline-script
feat: Python Script example that can take an input using an expression
- Loading branch information
Showing
1 changed file
with
54 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,54 @@ | ||
id: python-use-input-in-inline-script | ||
namespace: company.team | ||
|
||
inputs: | ||
- id: pokemon | ||
type: STRING | ||
defaults: pikachu | ||
|
||
- id: your_age | ||
type: INT | ||
defaults: 25 | ||
|
||
tasks: | ||
- id: inline_script | ||
type: io.kestra.plugin.scripts.python.Script | ||
description: Fetch the pokemon detail and compare its experience | ||
taskRunner: | ||
type: io.kestra.plugin.scripts.runner.docker.Docker | ||
containerImage: ghcr.io/kestra-io/pydata:latest | ||
script: | | ||
import requests | ||
import json | ||
url = "https://pokeapi.co/api/v2/pokemon/{{ inputs.pokemon }}" | ||
response = requests.get(url) | ||
if response.status_code == 200: | ||
pokemon = json.loads(response.text) | ||
print(f"Base experience of {{ inputs.pokemon }} is { pokemon.get('base_experience') }") | ||
if pokemon.get('base_experience') > int("{{ inputs.your_age }}"): | ||
print("{{ inputs.pokemon }} has more base experience than your age") | ||
else: | ||
print("{{ inputs.pokemon}} is too young!") | ||
else: | ||
print(f"Failed to retrieve the webpage. Status code: {response.status_code}") | ||
extend: | ||
title: Create a Python inline script that takes input using an expression | ||
description: >- | ||
This flow shows how you can use an input using an expression in Python inline script. | ||
The script takes two inputs, a string and an integer. Both the variables are being using in the | ||
Python code written as inline script. | ||
The Python script runs in a Docker container by default. In this case, we have explicitly mentioned the taskRunner as | ||
Docker and provided an image for the Docker container. Kestra ensures that the inputs are resolved even when the script | ||
runs using any of the taskRunners. | ||
tags: | ||
- Python | ||
- Inputs | ||
ee: false | ||
demo: true | ||
meta_description: This flow shows how you can take an input using an expression and use it in inline Python script. |