Python Execution Service
Overview
The Python Execution Service executes uploaded .py scripts as jobs. Runtime parameters can come from optional macros (in the job config) or a plain .env file loaded inside the script. Only core job metadata (e.g., jobId, engineType, packageName) is required; the macros section is optional.
Architecture
- Engine Service:
PythonExecutionService- lifecycle (init,run,stop,close) - Command Builder:
PythonCommandBuilder- builds command + environment variables from macros (if any) - Engine Validator:
PythonEngineValidator- validates Python installation path & executable - Configuration:
python.enabled,python.installPathinapplication.properties
Configuration (application.properties)
python.enabled=true
python.installPath=/Library/Frameworks/Python.framework/Versions/3.13
Execution Workflow
- Upload
app.py(optionally.env). - (Optional) Define macros in job config OR rely solely on
.env. - Validator checks configured Python install path.
- Engine runs
python3 app.py(fallbackpython). - Merged stdout/stderr streamed to job log.
Macros (Optional)
- Defined under
runtimeConfig.macrosin the job config JSON (optional section). - Each macro becomes an environment variable before the process starts.
- Secure values (
secure=true) decrypted prior to injection. - Missing or null values are skipped silently.
- If you omit
macros, no variables are injected this way (only those you load from.envinside the script).
Access pattern inside Python:
import os
value = os.getenv("MACRO_NAME")
Bulk Injection via .env
.env is a plain text file of KEY=VALUE entries (NOT JSON). It provides an alternative to manual macro creation. User can upload the .env file to jobconfig files and run the job.
Upload workflow:
- Include
.envalongsideapp.py - Platform may auto-convert entries to macros (optional)
- If not converted, load with
python-dotenvinside the script
.env File (Alternative / Complement)
- Plain text
KEY=VALUElines (NOT JSON). - Not auto-loaded by the worker; your script must load it (e.g.
python-dotenv) unless the platform separately converts entries into macros. - Supports comments starting with
#. - Quotes optional; recommended for values with spaces.
Sample .env:
APP_NAME="HelloWorld Demo"
APP_VERSION=1.0.0
APP_AUTHOR=Author1
Loading inside app.py when macros are not used:
from dotenv import load_dotenv
load_dotenv(override=True)
Choosing Between Macros and .env
- Use macros when you want immediate environment variables without code changes.
- Use
.envonly when you prefer bundling parameters with the script and are willing to load them in code. Parameters can be injected via macros or a bulk.envfile. On-premise users configure Python inapplication.properties. - Both can coexist; macros override same-named variables loaded from
.envif present first.
Example Script app.py
import os
try:
from dotenv import load_dotenv
load_dotenv(override=True)
except ImportError:
pass
app_name = os.getenv("APP_NAME", "UnknownApp")
app_version = os.getenv("APP_VERSION", "0.0.0")
app_author = os.getenv("APP_AUTHOR", "UnknownAuthor")
print(f"Hello from {app_name}")
print(f"Version: {app_version}")
print(f"Author: {app_author}")
Omit the macros object entirely if relying only on .env.
Inline .env Sample (Full)
APP_NAME=HelloWorld Demo
APP_VERSION=1.0.0
APP_AUTHOR=Author1
Error Handling
- Blank or invalid
python.installPath: job fails before execution. - No executable
python/python3found: validation failure. - Secure macro decryption failure: warns; skips that variable.
- Missing macro or
.envkey: script uses default fallback.
Security
- Mark sensitive macro values with
secure=true(encrypted at rest; decrypted before launch). - Plain
.envvalues are not decrypted; avoid storing secrets there if macros are available. - Only uploaded
.pyfiles are executed.
Troubleshooting
- Variable missing: confirm macro exists OR that
python-dotenvis installed and.envpresent. - Path issues: verify
python.installPathand permissions. - Unexpected defaults: ensure no typos in key names.
Future Enhancements
- Virtual environment / venv activation.
- Dependency installation hook.
- Structured result metadata and exit code mapping.
Checklist
python.enabled=trueset.- Valid
python.installPathwith executable. app.pyuploaded;packageNamematches.- (Optional) Macros defined OR
.envuploaded. - Secure values flagged where needed.