This article explains the Python keywords and functions that cannot be used in Assette Data Block definitions, the reasons behind these restrictions, and the correct way to return data from a block.
To maintain security and prevent misuse of the execution environment, certain Python names are forbidden in Data Block definitions. Any attempt to use these names will result in an error when the Data Block is executed.
Restricted Keywords #
Keyword | Description |
---|---|
type | Prevents access to the Python type() constructor to avoid runtime type manipulation. |
globals | Prevents access to global symbol tables. |
locals | Prevents access to local symbol tables. |
vars | Restricts access to object attribute dictionaries. |
dir | Prevents listing of accessible attributes. |
input | Prevents requesting input from the user during execution. |
help | Blocks access to Python’s interactive help system. |
Restricted Functions #
Function | Description |
---|---|
__subclasses__ | Prevents inspection of all subclasses of a given class. |
open | Blocks file reading and writing operations. |
exit | Prevents termination of the interpreter. |
quit | Prevents termination of the interpreter. |
exec | Prevents dynamic execution of Python code. |
eval | Prevents evaluation of arbitrary Python expressions. |
compile | Prevents compilation of dynamic Python code. |
memoryview | Blocks creation of memory view objects. |
Using “print()” in Data Blocks #
The “print()” function is not restricted and can be used in code. However, it does not contribute to the returned result of the block. Output from “print()” is not captured or included in the Data Block’s returned payload.
If you want to send data back from a block, you must explicitly assign it to the “response” object.
Returning Data from a Data Block #
To return data, assign it to one or more keys in the “response” dictionary.
Example #
outputData = 123
print(outputData) # Will not appear in returned data
response["data"] = = outputData # Correct way to return data
Best Practices #
- Use the “response” dictionary for all returned data.
- Avoid all restricted keywords and functions listed above.
- Treat “print()” only as a tool for debugging, not for returning results.