YepCode Python Code Rules
This file provides guidelines for LLMs to write Python code compatible with YepCode platform and ready to use its specific helpers.
Python Code Rules
Section titled “Python Code Rules”Code Structure (Python)
Section titled “Code Structure (Python)”- Use Python 3.13 features
- Define main() function for debugging support
- Use type hints when appropriate
- Follow PEP 8 style guidelines
Code Template (Python)
Section titled “Code Template (Python)”def main(): # Access input parameters parameters = yepcode.context.parameters
# Your code here
# Return result return { "message": "Success!" }Helpers Usage (Python)
Section titled “Helpers Usage (Python)”- Access execution info:
id, comment = yepcode.execution.id, yepcode.execution.comment - Access process info:
processId, processName = yepcode.execution.process.id, yepcode.execution.process.name - Access schedule info:
scheduleId, scheduleComment = yepcode.execution.get("schedule", {}).values() - Access team timezone:
timezone = yepcode.execution.timezone - Use environment variables:
api_key = os.getenv("API_KEY") # (or yepcode.env.API_KEY) - Import YepCode modules:
my_func = yepcode.import_module("module-name")- Caution: you can’t use variables as module names, just hardcoded strings
- Import YepCode modules with specific version:
my_func = yepcode.import_module("module-name", "v1.0") - Run another process:
yepcode.processes.run("process-identifier", options)
Logging (Python)
Section titled “Logging (Python)”print("INFO message") # Generates INFO level loglogger.debug("DEBUG message")logger.info("INFO message")logger.warn("WARNING message")logger.error("ERROR message")Dependencies Management (Python)
Section titled “Dependencies Management (Python)”- You may use external npm packages
- Just add the require statement to the code and the package will be installed automatically
- If package import name is different than the package name, you must use the the add-package comment:
# @add-package requestsimport requestsLocal Disk (Python)
Section titled “Local Disk (Python)”import os
# Calculate the path to the temporary filefile_path = os.path.join(os.environ.get("TMP_DATA_DIR"), "myfile.txt")
# Writing a filewith open(file_path, 'w') as f: f.write('Hello from YepCode!')Datastore (Python)
Section titled “Datastore (Python)”# Setting a valueyepcode.datastore.set("key", "value");
# Setting a object valueyepcode.datastore.set("key", json.dumps({ "name": "John", "age": 30 }));
# Getting a valuevalue = yepcode.datastore.get("key");
# Deleting a valueyepcode.datastore.delete("key");Storage (Python)
Section titled “Storage (Python)”import oslocal_path = os.path.join(os.environ.get("TMP_DATA_DIR"), "localfile.txt")
// Uploading a filewith open(local_path, "rb") as f: obj = yepcode.storage.upload("path/myfile.txt", f) print("Uploaded:", obj.name, obj.size, obj.link)
// Listing filesobjects = yepcode.storage.list()
// Downloading a filecontent = yepcode.storage.download("path/myfile.txt")with open(local_path, "wb") as f: f.write(content)
// Deleting a fileyepcode.storage.delete("path/myfile.txt")Return Values (Python)
Section titled “Return Values (Python)”Standard Return
Section titled “Standard Return”return { "message": "Success!" }Custom HTTP Status Codes
Section titled “Custom HTTP Status Codes”- This is the format for custom HTTP status codes:
return { "status": 404, "body": { "message": "Not found" }, "headers": { "Content-Type": "application/json" }}Transient Results (Python)
Section titled “Transient Results (Python)”return { "transient": True, "data": sensitive_data}