python
language runtime in language dropdownprint
at any time in a Python code step to log information as the script is running.
The output for the print
logs will appear in the Results
section just beneath the code editor.
requests
for making HTTP requestssqlalchemy
for retrieving or inserting data in a SQL databasepandas
for working with complex datasetsrequirements.txt
or specify elsewhere in your workflow of which packages you need. Pipedream will automatically install the dependency for you.
import
name differs from its PyPI package namepipreqs
package to detect package imports and install the associated package for you. Some packages, like python-telegram-bot
, use an import
name that differs from their PyPI name:
import
in your step. By default, Pipedream deploys the latest version of the PyPi package each time you deploy a change.
There are many cases where you may want to specify the version of the packages you’re using. If you’d like to use a specific version of a package in a workflow, you can add that version in a magic comment, for example:
requests
HTTP client package available in Python to send HTTP requests.
No need to run pip install
, just import requests
at the top of your step’s code and it’s available for your code to use.
See the Making HTTP Requests with Python docs for more information.
pd.respond()
method:
body
and status
keys in your pd.respond
argument. The body
must also be a JSON serializable object or dictionary.
pd.respond
helper does not yet support responding with Streams.pd.steps
object.
In this example, we’ll pretend this data is coming into our workflow’s HTTP trigger via POST request.
pd.steps
object passed into the handler
. Specifically, this data from the POST request into our workflow is available in the trigger
dictionary item.
return
the data in the handler
function:
pokemon
data is accessible to downstream steps within pd.steps["code"]["pokemon"]
os
module.
os
module to access your environment variables.os.environ["ENV_NAME_HERE"]
will raise an error that stops your workflow if that key doesn’t exist in your Pipedream account.Whereas os.environ.get("ENV_NAME_HERE")
will not throw an error and instead returns an empty string.If your code relies on the presence of a environment variable, consider using os.environ["ENV_NAME_HERE"]
instead.raise
an error to halt a step’s execution.
user_id
contained in the event to look up information in an external API. If you can’t find data in the API tied to that user, you don’t want to proceed.return pd.flow.exit()
will end the execution of the workflow immediately. No remaining code in that step, and no code or destination steps below, will run for the current event.
return pd.flow.exit()
to immediately exit the workflow. In contrast, pd.flow.exit()
on its own will end the workflow only after executing all remaining code in the step.pd.flow.exit()
:
/tmp
directory is accessible from your workflow steps for saving and retrieving files.
You have full access to read and write both files in /tmp
.
See the Working with the filesystem in Python docs for more information.
def handler(pd)
and the pipedream
package for Python code steps?ECONNRESET
error.
If you need to use data from other steps or export data to other steps in your workflow, we recommend using the pipedream
package module.
If you need to use a Data Store in your workflow, we recommend using a pre-built action to retrieve or store data or Node.js’s Data Store capabilities.