Hi, I’m newbie on pipedream and trying to do python integration.
My goal is to summarize content from url link from trigger using python code, It works when I add url manually on the python code, but if I add the variable from trigger, it’s always error. Is there anything I need to do so Python code can read url result from trigger correctly?
Hello @rifqihive, first of all welcome to Pipedream!
To have the steps data available in your Pythong step, you can wrap your code inside a handler function like this:
def handler(pd: "pipedream"):
# Reference data from previous steps
url = pd.steps["trigger"]["event"]["content"]
# Your code here...
# Return data for use in future steps
return text
You can refer to Python Code examples by tapping “Code Examples” button
Thanks for your help, really appreciated. So I’ve used your code and it said successfully exported, my next question is how we can use the result of the previous steps on next step? In my case it’s a url link.
Thank you for your respond, I’ve tried it and it’s not working, it seems the problem is that I’m using python step and there is different way to pass the variable between steps on pipedream, and I’m not sure how to do it. Cheers.
Yes I’ve actually read it and since I’m not well versed with coding and python, I think I’ve done the export but I’m not sure how exactly to put the result from previous steps into python workflow. In my case it’s a url from trigger.
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = 'handler' ## what code to put here so the python code can load url result from my trigger result?
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")
My goal is simply to make the python code can load the url data from previous trigger step, usually I can just paste the code, but it seems python has a different workflow?
@rifqihive you should wrap your code inside a handler function and reference to the pd param, something like this
from urllib.request import urlopen
from bs4 import BeautifulSoup
def handler(pd: "pipedream"):
# Reference data from trigger
url = pd.steps["trigger"]["event"]["content"]
# Open the URL and parse the HTML
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")
# Return data for use in future steps
return soup
Note that I’m not familiar with Python (I’m more on Node.js side), and I have not tested the code above.