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âQuick Reference
Section titled âQuick Referenceâ| Aspect | Guideline |
|---|---|
| Runtime | Python 3.13 |
| Main file (process) | main.py |
| Entry point | def main() |
| Parameters | yepcode.context.parameters |
| Variables | os.getenv("X") or yepcode.env.X |
| Modules | yepcode.import_module("module-slug") |
Critical Rules
Section titled âCritical Rulesâ- â
Always define a
main()function - â Never call
main()directly - â
Always add
try/exceptaround the main flow for actionable errors - â Follow PEP 8 (and add type hints when useful)
- â Always use snake_case for variables and functions
- â Never use dynamic module names with
yepcode.import_module()âmodule names must be hardcoded strings (e.g.yepcode.import_module("module-name")), not variables
Process Template
Section titled âProcess Templateâdef main(): # Access input parameters parameters = yepcode.context.parameters
# Your code here
# Return result return { "message": "Success!" }Helpers Usage
Section titled âHelpers Usageâ- Access execution info:
execution_id = yepcode.execution.id - Access process info:
process_id = yepcode.execution.process.id - Access schedule info (if present):
scheduleId, scheduleComment = yepcode.execution.schedule.id, yepcode.execution.schedule.comment - Access team timezone:
timezone = yepcode.execution.timezone - Use environment variables:
api_key = os.getenv("API_KEY") # or yepcode.env.API_KEY - Import YepCode modules:
client = yepcode.import_module("module-name")- Caution: module names must be hardcoded strings (no variables)
- Import with version:
client = yepcode.import_module("module-name", "v1.0") - Run another process:
yepcode.processes.run("process-identifier", options)
Logging
Section titled âLoggingâprint("INFO message") # Generates INFO level loglogger.debug("DEBUG message")logger.info("INFO message")logger.warn("WARNING message")logger.error("ERROR message")Dependencies Management
Section titled âDependencies Managementâ- You may use external pip packages.
- Just add the
importstatement and the package will be installed automatically. - If the package name differs from the import name, use the
@add-packagecomment:
# @add-package requestsimport requestsLocal Disk
Section titled âLocal Diskâ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
Section titled âDatastoreâimport json
# 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
Section titled âStorageâ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
Section titled âReturn Valuesâ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
Section titled âTransient Resultsâreturn { "transient": True, "data": sensitive_data}Do & Donât
Section titled âDo & DonâtâDo
- Define
main()and avoid calling it directly. - Validate parameters at the start; raise meaningful errors for missing or invalid input.
- Use environment variables (e.g.
os.getenv("API_KEY")) for secrets; never hardcode them. - Use try/except around the main flow and log or re-raise with clear messages.
- Use snake_case for variables and functions; follow PEP 8.
- Use type hints where helpful.
- Log important steps; never log secrets.
Donât
- Never call
main()in your codeâYepCode invokes it. - Never hardcode API keys, passwords, or tokens.
- Donât use camelCase in Python; use snake_case.
- Donât ignore errors; wrap risky operations in try/except.
- Donât use dynamic module names:
yepcode.import_module(module_name)is wrong; useyepcode.import_module("module-name"). - Donât rely on global variables for state; pass state through parameters or return values.