Workflow Custom Code Writing Standards
Background: For security reasons, [python custom skill code] && [advanced orchestration - code node] require standardized code writing instructions.
Supported Python Packages
1. Built-in Functions and Types
dictsortedfiltermapenumerate
2. Standard Library Modules
Data Processing
jsondecimaluuidbase64hashlib
String Processing
re(regular expressions)stringtextwrapdifflib(difference comparison)
Data Structures and Algorithms
copybisect(binary search)heapq(heap queue)statistics(statistical calculations)
Mathematical Computation
mathoperator(operator functions)
Date and Time
datetimetimecalendar
Other Utilities
random(random number generation)requests(HTTP requests)
3. Type Annotations (typing module)
typing(the module itself)AnyUnionOptionalLiteralFinalClassVarTypeVarGenericProtocolruntime_checkableoverloadcastTYPE_CHECKINGNoReturnListDictSetTupleFrozenSetDequeCounterChainMapOrderedDictDefaultDictMutableMappingMutableSequenceMutableSetMappingSequenceAbstractSetCollectionContainerIterableIteratorReversibleSizedHashableCallableAwaitableCoroutineAsyncIterableAsyncIteratorAsyncGeneratorGeneratorContextManagerAsyncContextManager
Syntax Standards
Due to the use of secure environment isolation and other restrictions, writers need to follow relevant standards when writing code. Premise: Only built-in syntax and built-in libraries, as well as a limited set of standard libraries, are supported.
- Using the math module
import math
def calculate(a, b):
result = math.fsum([a, b])
return result
Incorrect usage:
from math import fsum
def calculate(a, b):
result = fsum([a, b])
return result
Explanation: Due to current import restrictions in the code block, only parent package imports are supported when using import. The syntax from a import b is not supported.
- Using datetime
Correct usage:
import typing
from datetime import datetime
def get_weather(location: str, date: typing.Optional[str] = None) -> dict:
# Handle default date
if date is None:
formatted_date = datetime.datetime.now().strftime("%Y-%m-%d")
else:
try:
# Try to parse common date formats
if len(date) == 8 and date.isdigit():
# Handle YYYYMMDD format
date_obj = datetime.datetime.strptime(date, "%Y%m%d")
else:
# Try standard format YYYY-MM-DD
date_obj = datetime.datetime.strptime(date, "%Y-%m-%d")
formatted_date = date_obj.strftime("%Y-%m-%d")
except ValueError:
# If the format does not match, use the original input (may cause API call failure)
formatted_date = date
# This is mock data; in actual use, you may call a weather API
weather_data = {
"location": location,
"date": formatted_date,
"forecast": "sunny",
"temperature": "25°C",
"wind": "light breeze"
}
return weather_data
Incorrect usage:
from typing import Optional, List, Dict, Any, Union, Callable
from datetime import datetime
...省略...