Asynchronous Python Executor
Our Run Asynchronous Python Code (Advanced)
module allows you to run Python
code for up to 30 minutes (compared to only 3 minutes for the
normal Python executor). The tradeoff is that you need to get the
result asynchronously via a webhook or polling. You can find the API docs
here.
Overview
You can configure three things here:
Code
is your Python code itself. This will be executed by our code executor, just like when you runpython
yourself locally.
In contrast to the non-async Python executor, you can use print
in the async
Python executor. Assigning data to the global result
variable will have no
effect.
Requirements
are the PyPI packages you want to use. These are passed verbatim topip
(which you can also use locally).
Don't pass standard library packages here, like json
. These are already
installed (like in every Python environment), and won't be found on PyPI.
Remember, the Requirements
are passed directly to pip.
Send To
is your webhook URL. See below for more information.
Getting Results
Unfortunately, platforms like Make impose HTTP timeouts, and we therefore cannot execute code in a single connection for arbitrary amounts of time. Our solution is to give you the results asynchronously. This does complicate your workflow a little, but there is currently no other option.
This section will describe the two different options you have to retrieve your results after your code has finished executing.
Webhooks
If you provide a webhook URL in the Send To
field, the async Python executor
will send an HTTP POST
request to this webhook once your Python code has
finished executing. The request body will look like this:
{
"status": "success",
"result": "Hello, world!\n",
"endpoint": "/code/async-python"
}
You can create a webhook in Make relatively easily using the Custom Webhook
module:
The shown webhook URL has to be pasted into the Send To
field. The rest of
your workflow can continue from this webhook node and use the results of your
Python code.
It makes sense to print a JSON value to the console and then parse that with the
Make module Parse JSON
to easily process the result.
Task Status
In most cases, it is significantly easier to use webhooks for this. Only use this module if you are sure that webhooks don't work for your purpose.
If you do not want to use a webhook, you can also poll the results regularly.
You can use the task ID provided to you by the
Run Asynchronous Python Code (Advanced)
module, and you will get the current
status, and the results if your code is done already.
Pricing
The asynchronous Python executor can run up to 30 minutes, and costs 50 credits per every started 3 minutes of execution. If you execute code for 2 minutes, this will cost 50 credits, 7 minutes will cost 150, and 30 minutes will cost 500.