Python Executor
Our Run Python Code module allows you to run Python code on the CPython
runtime, inside a relatively standard Linux environment. You can find the API
docs here.
Overview

You can configure three things here:
Your Python Codeis the code itself. This is what will be executed by our code executor. It works pretty much exactly like when you runpythonlocally (with the CPython runtime).
In the non-async Python executor, the only way to get a result is by assigning
to the global result variable. Printing something to the console has no
effect. Make sure that the value assigned to the result variable is
JSON-serializable.
Requirementsare 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.
You can also leave the Requirements field empty, and let the Python executor
infer which packages you are using. However, this is deprecated, and should
definitely not be used anymore. It may break at any time! If you are using any
additional PyPI packages, always put them into the Requirements array.
System Dependenciesare packages that should be installed on the system before running your code. This is an advanced feature, you don't need this most of the time. Common usecases are when you want to use ffmpeg to manipulate audio or use a webdriver like Selenium.
We're using the Alpine Package Keeper for installing system dependencies, you can find all available packages here.
Pricing
The Python executor (not to be confused with the async Python executor) costs 50 credits per execution (of up to 3 minutes).
Examples
This section presents a couple of very basic Python examples. They are mostly there to show how to return data from the code executor. If you want to learn Python itself, take a look here.
def multiplyNumbers(number1, number2):
return = number1 * number2
result = {
"data": multiplyNumbers(43, 11)
}
// TODO: add "numpy" to your requirements
import numpy
array = numpy.random.randint(1000, size=(8))
index = 0
for number in array:
result['randInt'+str(index)] = str(array[index])
index += 1
"""
output:
{
"result": {
"randInt0": "819",
"randInt1": "794",
"randInt2": "181",
"randInt3": "811",
"randInt4": "205",
"randInt5": "187",
"randInt6": "697",
"randInt7": "141",
}
}
"""
// TODO: add "requests" to your requirements
import requests
result = requests.get('https://www.0codekit.com').text