mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 08:01:25 +00:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
export default `import os
|
|
import wmill
|
|
|
|
# You can import any PyPi package.
|
|
# See here for more info: https://docs.windmill.dev/docs/advanced/imports#python
|
|
|
|
# you can use typed resources by doing a type alias to dict
|
|
#postgresql = dict
|
|
|
|
def main(
|
|
no_default: str,
|
|
#db: postgresql,
|
|
name="Nicolas Bourbaki",
|
|
age=42,
|
|
obj: dict = {"even": "dicts"},
|
|
l: list = ["or", "lists!"],
|
|
file_: bytes = bytes(0),
|
|
):
|
|
|
|
print(f"Hello World and a warm welcome especially to {name}")
|
|
print("and its acolytes..", age, obj, l, len(file_))
|
|
|
|
# retrieve variables, resources, states using the wmill client
|
|
try:
|
|
secret = wmill.get_variable("f/examples/secret")
|
|
except:
|
|
secret = "No secret yet at f/examples/secret !"
|
|
print(f"The variable at \`f/examples/secret\`: {secret}")
|
|
|
|
# Get last state of this script execution by the same trigger/user
|
|
last_state = wmill.get_state()
|
|
new_state = {"foo": 42} if last_state is None else last_state
|
|
new_state["foo"] += 1
|
|
wmill.set_state(new_state)
|
|
|
|
# fetch context variables
|
|
user = os.environ.get("WM_USERNAME")
|
|
|
|
# return value is converted to JSON
|
|
return {"splitted": name.split(), "user": user, "state": new_state}`
|