@trigger.dev/python 0.0.0-prerelease-20250226191317

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Trigger.dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Python Extension for Trigger.dev
2
+
3
+ The Python extension enhances Trigger.dev's build process by enabling limited support for executing Python scripts within your tasks.
4
+
5
+ ## Overview
6
+
7
+ This extension introduces the <code>pythonExtension</code> build extension, which offers several key capabilities:
8
+
9
+ - **Install Python Dependencies (Except in Dev):** Automatically installs Python and specified dependencies using <code>pip</code>.
10
+ - **Requirements File Support:** You can specify dependencies in a <code>requirements.txt</code> file.
11
+ - **Inline Requirements:** Define dependencies directly within your <code>trigger.config.ts</code> file using the <code>requirements</code> option.
12
+ - **Virtual Environment:** Creates a virtual environment (<code>/opt/venv</code>) inside containers to isolate Python dependencies.
13
+ - **Helper Functions:** Provides a variety of functions for executing Python code:
14
+ - <code>run</code>: Executes Python commands with proper environment setup.
15
+ - <code>runInline</code>: Executes inline Python code directly from Node.
16
+ - <code>runScript</code>: Executes standalone <code>.py</code> script files.
17
+ - **Custom Python Path:** In development, you can configure <code>devPythonBinaryPath</code> to point to a custom Python installation.
18
+
19
+ ## Usage
20
+
21
+ 1. Add the extension to your <code>trigger.config.ts</code> file:
22
+
23
+ ```typescript
24
+ import { defineConfig } from "@trigger.dev/sdk/v3";
25
+ import { pythonExtension } from "@trigger.dev/python/extension";
26
+
27
+ export default defineConfig({
28
+ project: "<project ref>",
29
+ build: {
30
+ extensions: [
31
+ pythonExtension({
32
+ requirementsFile: "./requirements.txt", // Optional: Path to your requirements file
33
+ devPythonBinaryPath: ".venv/bin/python", // Optional: Custom Python binary path
34
+ scripts: ["src/python/**/*.py"], // Glob pattern for Python scripts
35
+ }),
36
+ ],
37
+ },
38
+ });
39
+ ```
40
+
41
+ 2. (Optional) Create a <code>requirements.txt</code> file in your project root with the necessary Python dependencies.
42
+
43
+ ```plaintext title="requirements.txt"
44
+ pandas==1.3.3
45
+ numpy==1.21.2
46
+ ```
47
+
48
+ ```typescript title="trigger.config.ts"
49
+ import { defineConfig } from "@trigger.dev/sdk/v3";
50
+ import { pythonExtension } from "@trigger.dev/python/extension";
51
+
52
+ export default defineConfig({
53
+ project: "<project ref>",
54
+ build: {
55
+ extensions: [
56
+ pythonExtension({
57
+ requirementsFile: "./requirements.txt",
58
+ }),
59
+ ],
60
+ },
61
+ });
62
+ ```
63
+
64
+ 3. Execute Python scripts within your tasks using one of the provided functions:
65
+
66
+ ### Running a Python Script
67
+
68
+ ```typescript
69
+ import { task } from "@trigger.dev/sdk/v3";
70
+ import { python } from "@trigger.dev/python";
71
+
72
+ export const myScript = task({
73
+ id: "my-python-script",
74
+ run: async () => {
75
+ const result = await python.runScript("my_script.py", ["hello", "world"]);
76
+ return result.stdout;
77
+ },
78
+ });
79
+ ```
80
+
81
+ ### Running Inline Python Code
82
+
83
+ ```typescript
84
+ import { task } from "@trigger.dev/sdk/v3";
85
+ import { python } from "@trigger.dev/python";
86
+
87
+ export const myTask = task({
88
+ id: "to_datetime-task",
89
+ run: async () => {
90
+ const result = await python.runInline(`
91
+ import pandas as pd
92
+
93
+ pd.to_datetime("${+new Date() / 1000}")
94
+ `);
95
+ return result.stdout;
96
+ },
97
+ });
98
+ ```
99
+
100
+ ### Running Lower-Level Commands
101
+
102
+ ```typescript
103
+ import { task } from "@trigger.dev/sdk/v3";
104
+ import { python } from "@trigger.dev/python";
105
+
106
+ export const pythonVersionTask = task({
107
+ id: "python-version-task",
108
+ run: async () => {
109
+ const result = await python.run(["--version"]);
110
+ return result.stdout; // Expected output: Python 3.12.8
111
+ },
112
+ });
113
+ ```
114
+
115
+ ## Limitations
116
+
117
+ - This is a **partial implementation** and does not provide full Python support as an execution runtime for tasks.
118
+ - Manual intervention may be required for installing and configuring binary dependencies in development environments.
119
+
120
+ ## Additional Information
121
+
122
+ For more detailed documentation, visit the official docs at [Trigger.dev Documentation](https://trigger.dev/docs).
@@ -0,0 +1,23 @@
1
+ import { BuildExtension } from "@trigger.dev/core/v3/build";
2
+ export type PythonOptions = {
3
+ requirements?: string[];
4
+ requirementsFile?: string;
5
+ /**
6
+ * [Dev-only] The path to the python binary.
7
+ *
8
+ * @remarks
9
+ * This option is typically used during local development or in specific testing environments
10
+ * where a particular Python installation needs to be targeted. It should point to the full path of the python executable.
11
+ *
12
+ * Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
13
+ */
14
+ devPythonBinaryPath?: string;
15
+ /**
16
+ * An array of glob patterns that specify which Python scripts are allowed to be executed.
17
+ *
18
+ * @remarks
19
+ * These scripts will be copied to the container during the build process.
20
+ */
21
+ scripts?: string[];
22
+ };
23
+ export declare function pythonExtension(options?: PythonOptions): BuildExtension;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pythonExtension = pythonExtension;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_assert_1 = __importDefault(require("node:assert"));
9
+ const internal_1 = require("@trigger.dev/build/internal");
10
+ const splitAndCleanComments = (str) => str
11
+ .split("\n")
12
+ .map((line) => line.trim())
13
+ .filter((line) => line && !line.startsWith("#"));
14
+ function pythonExtension(options = {}) {
15
+ return new PythonExtension(options);
16
+ }
17
+ class PythonExtension {
18
+ options;
19
+ name = "PythonExtension";
20
+ constructor(options = {}) {
21
+ this.options = options;
22
+ (0, node_assert_1.default)(!(this.options.requirements && this.options.requirementsFile), "Cannot specify both requirements and requirementsFile");
23
+ if (this.options.requirementsFile) {
24
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(this.options.requirementsFile), `Requirements file not found: ${this.options.requirementsFile}`);
25
+ this.options.requirements = splitAndCleanComments(node_fs_1.default.readFileSync(this.options.requirementsFile, "utf-8"));
26
+ }
27
+ }
28
+ async onBuildComplete(context, manifest) {
29
+ await (0, internal_1.addAdditionalFilesToBuild)("pythonExtension", {
30
+ files: this.options.scripts ?? [],
31
+ }, context, manifest);
32
+ if (context.target === "dev") {
33
+ if (this.options.devPythonBinaryPath) {
34
+ process.env.PYTHON_BIN_PATH = this.options.devPythonBinaryPath;
35
+ }
36
+ return;
37
+ }
38
+ context.logger.debug(`Adding ${this.name} to the build`);
39
+ context.addLayer({
40
+ id: "python-installation",
41
+ image: {
42
+ instructions: splitAndCleanComments(`
43
+ # Install Python
44
+ RUN apt-get update && apt-get install -y --no-install-recommends \
45
+ python3 python3-pip python3-venv && \
46
+ apt-get clean && rm -rf /var/lib/apt/lists/*
47
+
48
+ # Set up Python environment
49
+ RUN python3 -m venv /opt/venv
50
+ ENV PATH="/opt/venv/bin:$PATH"
51
+ `),
52
+ },
53
+ deploy: {
54
+ env: {
55
+ PYTHON_BIN_PATH: `/opt/venv/bin/python`,
56
+ },
57
+ override: true,
58
+ },
59
+ });
60
+ if (this.options.requirementsFile) {
61
+ if (this.options.requirements) {
62
+ context.logger.warn(`[pythonExtension] Both options.requirements and options.requirementsFile are specified. requirements will be ignored.`);
63
+ }
64
+ // Copy requirements file to the container
65
+ await (0, internal_1.addAdditionalFilesToBuild)("pythonExtension", {
66
+ files: [this.options.requirementsFile],
67
+ }, context, manifest);
68
+ // Add a layer to the build that installs the requirements
69
+ context.addLayer({
70
+ id: "python-dependencies",
71
+ image: {
72
+ instructions: splitAndCleanComments(`
73
+ # Copy the requirements file
74
+ COPY ${this.options.requirementsFile} .
75
+ # Install dependencies
76
+ RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
77
+ `),
78
+ },
79
+ deploy: {
80
+ override: true,
81
+ },
82
+ });
83
+ }
84
+ else if (this.options.requirements) {
85
+ context.addLayer({
86
+ id: "python-dependencies",
87
+ build: {
88
+ env: {
89
+ REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
90
+ },
91
+ },
92
+ image: {
93
+ instructions: splitAndCleanComments(`
94
+ ARG REQUIREMENTS_CONTENT
95
+ RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
96
+
97
+ # Install dependencies
98
+ RUN pip install --no-cache-dir -r requirements.txt
99
+ `),
100
+ },
101
+ deploy: {
102
+ override: true,
103
+ },
104
+ });
105
+ }
106
+ }
107
+ }
108
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":";;;;;AAkCA,0CAEC;AApCD,sDAAyB;AACzB,8DAAiC;AACjC,0DAAwE;AA0BxE,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAAE,CAC5C,GAAG;KACA,KAAK,CAAC,IAAI,CAAC;KACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,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AAE,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;qBAClE;iBACF;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMrC,CAAC;iBACD;gBACD,MAAM,EAAE;oBACN,QAAQ,EAAE,IAAI;iBACf;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Options as XOptions, Result } from "tinyexec";
2
+ export declare const python: {
3
+ run(scriptArgs?: string[], options?: Partial<XOptions>): Promise<Result>;
4
+ runScript(scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>): Promise<Result>;
5
+ runInline(scriptContent: string, options?: Partial<XOptions>): Promise<Result>;
6
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.python = void 0;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_assert_1 = __importDefault(require("node:assert"));
9
+ const v3_1 = require("@trigger.dev/sdk/v3");
10
+ const tinyexec_1 = require("tinyexec");
11
+ const v3_2 = require("@trigger.dev/core/v3");
12
+ const tempFiles_js_1 = require("./utils/tempFiles.js");
13
+ exports.python = {
14
+ async run(scriptArgs = [], options = {}) {
15
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
16
+ return await v3_1.logger.trace("python.run()", async (span) => {
17
+ const result = await (0, tinyexec_1.x)(pythonBin, scriptArgs, {
18
+ ...options,
19
+ throwOnError: false, // Ensure errors are handled manually
20
+ });
21
+ if (result.exitCode) {
22
+ span.setAttribute("exitCode", result.exitCode);
23
+ }
24
+ if (result.exitCode !== 0) {
25
+ throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
26
+ }
27
+ return result;
28
+ }, {
29
+ attributes: {
30
+ pythonBin,
31
+ args: scriptArgs.join(" "),
32
+ [v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
33
+ },
34
+ });
35
+ },
36
+ async runScript(scriptPath, scriptArgs = [], options = {}) {
37
+ (0, node_assert_1.default)(scriptPath, "Script path is required");
38
+ (0, node_assert_1.default)(node_fs_1.default.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
39
+ return await v3_1.logger.trace("python.runScript()", async (span) => {
40
+ span.setAttribute("scriptPath", scriptPath);
41
+ const result = await (0, tinyexec_1.x)(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
42
+ ...options,
43
+ throwOnError: false,
44
+ });
45
+ if (result.exitCode) {
46
+ span.setAttribute("exitCode", result.exitCode);
47
+ }
48
+ if (result.exitCode !== 0) {
49
+ throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
50
+ }
51
+ return result;
52
+ }, {
53
+ attributes: {
54
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
55
+ scriptPath,
56
+ args: scriptArgs.join(" "),
57
+ [v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
58
+ },
59
+ });
60
+ },
61
+ async runInline(scriptContent, options = {}) {
62
+ (0, node_assert_1.default)(scriptContent, "Script content is required");
63
+ return await v3_1.logger.trace("python.runInline()", async (span) => {
64
+ span.setAttribute("contentLength", scriptContent.length);
65
+ // Using the withTempFile utility to handle the temporary file
66
+ return await (0, tempFiles_js_1.withTempFile)(`script_${Date.now()}.py`, async (tempFilePath) => {
67
+ span.setAttribute("tempFilePath", tempFilePath);
68
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
69
+ const result = await (0, tinyexec_1.x)(pythonBin, [tempFilePath], {
70
+ ...options,
71
+ throwOnError: false,
72
+ });
73
+ if (result.exitCode) {
74
+ span.setAttribute("exitCode", result.exitCode);
75
+ }
76
+ if (result.exitCode !== 0) {
77
+ throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
78
+ }
79
+ return result;
80
+ }, scriptContent);
81
+ }, {
82
+ attributes: {
83
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
84
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
85
+ [v3_2.SemanticInternalAttributes.STYLE_ICON]: "brand-python",
86
+ },
87
+ });
88
+ },
89
+ };
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,8DAAiC;AACjC,4CAA6C;AAC7C,uCAA0D;AAC1D,6CAAkE;AAClE,uDAAoD;AAEvC,QAAA,MAAM,GAAG;IACpB,KAAK,CAAC,GAAG,CAAC,aAAuB,EAAE,EAAE,UAA6B,EAAE;QAClE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ,CAAC;QAE1D,OAAO,MAAM,WAAM,CAAC,KAAK,CACvB,cAAc,EACd,KAAK,EAAE,IAAI,EAAE,EAAE;YACb,MAAM,MAAM,GAAG,MAAM,IAAA,YAAC,EAAC,SAAS,EAAE,UAAU,EAAE;gBAC5C,GAAG,OAAO;gBACV,YAAY,EAAE,KAAK,EAAE,qCAAqC;aAC3D,CAAC,CAAC;YAEH,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;YAED,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CACb,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,gCAAgC,MAAM,CAAC,QAAQ,MACpE,MAAM,CAAC,MACT,EAAE,CACH,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,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S,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,QAAQ;gBAClD,cAAc,EACZ,aAAa,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7E,CAAC,+BAA0B,CAAC,UAAU,CAAC,EAAE,cAAc;aACxD;SACF,CACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
3
+ * @param filename The filename to use for the temporary file
4
+ * @param callback Function that receives the path to the temporary file
5
+ * @param content Optional content to write to the file
6
+ * @returns Whatever the callback returns
7
+ */
8
+ export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withTempFile = withTempFile;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_os_1 = require("node:os");
6
+ const node_path_1 = require("node:path");
7
+ /**
8
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
9
+ * @param filename The filename to use for the temporary file
10
+ * @param callback Function that receives the path to the temporary file
11
+ * @param content Optional content to write to the file
12
+ * @returns Whatever the callback returns
13
+ */
14
+ async function withTempFile(filename, callback, content = "") {
15
+ // Create temporary directory with random suffix
16
+ const tempDir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "app-"));
17
+ const tempFile = (0, node_path_1.join)(tempDir, filename);
18
+ try {
19
+ // Write to the temporary file with appropriate permissions
20
+ await (0, promises_1.writeFile)(tempFile, content, { mode: 0o600 });
21
+ // Use the file
22
+ return await callback(tempFile);
23
+ }
24
+ finally {
25
+ // Clean up
26
+ await (0, promises_1.rm)(tempDir, { recursive: true, force: true });
27
+ }
28
+ }
29
+ //# sourceMappingURL=tempFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tempFiles.js","sourceRoot":"","sources":["../../../src/utils/tempFiles.ts"],"names":[],"mappings":";;AAWA,oCAkBC;AA7BD,+CAA0D;AAC1D,qCAAiC;AACjC,yCAAiC;AAEjC;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,QAA0C,EAC1C,UAA2B,EAAE;IAE7B,gDAAgD;IAChD,MAAM,OAAO,GAAG,MAAM,IAAA,kBAAO,EAAC,IAAA,gBAAI,EAAC,IAAA,gBAAM,GAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAA,gBAAI,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAI,CAAC;QACH,2DAA2D;QAC3D,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,eAAe;QACf,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,WAAW;QACX,MAAM,IAAA,aAAE,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { BuildExtension } from "@trigger.dev/core/v3/build";
2
+ export type PythonOptions = {
3
+ requirements?: string[];
4
+ requirementsFile?: string;
5
+ /**
6
+ * [Dev-only] The path to the python binary.
7
+ *
8
+ * @remarks
9
+ * This option is typically used during local development or in specific testing environments
10
+ * where a particular Python installation needs to be targeted. It should point to the full path of the python executable.
11
+ *
12
+ * Example: `/usr/bin/python3` or `C:\\Python39\\python.exe`
13
+ */
14
+ devPythonBinaryPath?: string;
15
+ /**
16
+ * An array of glob patterns that specify which Python scripts are allowed to be executed.
17
+ *
18
+ * @remarks
19
+ * These scripts will be copied to the container during the build process.
20
+ */
21
+ scripts?: string[];
22
+ };
23
+ export declare function pythonExtension(options?: PythonOptions): BuildExtension;
@@ -0,0 +1,102 @@
1
+ import fs from "node:fs";
2
+ import assert from "node:assert";
3
+ import { addAdditionalFilesToBuild } from "@trigger.dev/build/internal";
4
+ const splitAndCleanComments = (str) => str
5
+ .split("\n")
6
+ .map((line) => line.trim())
7
+ .filter((line) => line && !line.startsWith("#"));
8
+ export function pythonExtension(options = {}) {
9
+ return new PythonExtension(options);
10
+ }
11
+ class PythonExtension {
12
+ options;
13
+ name = "PythonExtension";
14
+ constructor(options = {}) {
15
+ this.options = options;
16
+ assert(!(this.options.requirements && this.options.requirementsFile), "Cannot specify both requirements and requirementsFile");
17
+ if (this.options.requirementsFile) {
18
+ assert(fs.existsSync(this.options.requirementsFile), `Requirements file not found: ${this.options.requirementsFile}`);
19
+ this.options.requirements = splitAndCleanComments(fs.readFileSync(this.options.requirementsFile, "utf-8"));
20
+ }
21
+ }
22
+ async onBuildComplete(context, manifest) {
23
+ await addAdditionalFilesToBuild("pythonExtension", {
24
+ files: this.options.scripts ?? [],
25
+ }, context, manifest);
26
+ if (context.target === "dev") {
27
+ if (this.options.devPythonBinaryPath) {
28
+ process.env.PYTHON_BIN_PATH = this.options.devPythonBinaryPath;
29
+ }
30
+ return;
31
+ }
32
+ context.logger.debug(`Adding ${this.name} to the build`);
33
+ context.addLayer({
34
+ id: "python-installation",
35
+ image: {
36
+ instructions: splitAndCleanComments(`
37
+ # Install Python
38
+ RUN apt-get update && apt-get install -y --no-install-recommends \
39
+ python3 python3-pip python3-venv && \
40
+ apt-get clean && rm -rf /var/lib/apt/lists/*
41
+
42
+ # Set up Python environment
43
+ RUN python3 -m venv /opt/venv
44
+ ENV PATH="/opt/venv/bin:$PATH"
45
+ `),
46
+ },
47
+ deploy: {
48
+ env: {
49
+ PYTHON_BIN_PATH: `/opt/venv/bin/python`,
50
+ },
51
+ override: true,
52
+ },
53
+ });
54
+ if (this.options.requirementsFile) {
55
+ if (this.options.requirements) {
56
+ context.logger.warn(`[pythonExtension] Both options.requirements and options.requirementsFile are specified. requirements will be ignored.`);
57
+ }
58
+ // Copy requirements file to the container
59
+ await addAdditionalFilesToBuild("pythonExtension", {
60
+ files: [this.options.requirementsFile],
61
+ }, context, manifest);
62
+ // Add a layer to the build that installs the requirements
63
+ context.addLayer({
64
+ id: "python-dependencies",
65
+ image: {
66
+ instructions: splitAndCleanComments(`
67
+ # Copy the requirements file
68
+ COPY ${this.options.requirementsFile} .
69
+ # Install dependencies
70
+ RUN pip install --no-cache-dir -r ${this.options.requirementsFile}
71
+ `),
72
+ },
73
+ deploy: {
74
+ override: true,
75
+ },
76
+ });
77
+ }
78
+ else if (this.options.requirements) {
79
+ context.addLayer({
80
+ id: "python-dependencies",
81
+ build: {
82
+ env: {
83
+ REQUIREMENTS_CONTENT: this.options.requirements?.join("\n") || "",
84
+ },
85
+ },
86
+ image: {
87
+ instructions: splitAndCleanComments(`
88
+ ARG REQUIREMENTS_CONTENT
89
+ RUN echo "$REQUIREMENTS_CONTENT" > requirements.txt
90
+
91
+ # Install dependencies
92
+ RUN pip install --no-cache-dir -r requirements.txt
93
+ `),
94
+ },
95
+ deploy: {
96
+ override: true,
97
+ },
98
+ });
99
+ }
100
+ }
101
+ }
102
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension.js","sourceRoot":"","sources":["../../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AA0BxE,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAAE,CAC5C,GAAG;KACA,KAAK,CAAC,IAAI,CAAC;KACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC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YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;qBAClE;iBACF;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,qBAAqB,CAAC;;;;;;SAMrC,CAAC;iBACD;gBACD,MAAM,EAAE;oBACN,QAAQ,EAAE,IAAI;iBACf;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import { Options as XOptions, Result } from "tinyexec";
2
+ export declare const python: {
3
+ run(scriptArgs?: string[], options?: Partial<XOptions>): Promise<Result>;
4
+ runScript(scriptPath: string, scriptArgs?: string[], options?: Partial<XOptions>): Promise<Result>;
5
+ runInline(scriptContent: string, options?: Partial<XOptions>): Promise<Result>;
6
+ };
@@ -0,0 +1,84 @@
1
+ import fs from "node:fs";
2
+ import assert from "node:assert";
3
+ import { logger } from "@trigger.dev/sdk/v3";
4
+ import { x } from "tinyexec";
5
+ import { SemanticInternalAttributes } from "@trigger.dev/core/v3";
6
+ import { withTempFile } from "./utils/tempFiles.js";
7
+ export const python = {
8
+ async run(scriptArgs = [], options = {}) {
9
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
10
+ return await logger.trace("python.run()", async (span) => {
11
+ const result = await x(pythonBin, scriptArgs, {
12
+ ...options,
13
+ throwOnError: false, // Ensure errors are handled manually
14
+ });
15
+ if (result.exitCode) {
16
+ span.setAttribute("exitCode", result.exitCode);
17
+ }
18
+ if (result.exitCode !== 0) {
19
+ throw new Error(`${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
20
+ }
21
+ return result;
22
+ }, {
23
+ attributes: {
24
+ pythonBin,
25
+ args: scriptArgs.join(" "),
26
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
27
+ },
28
+ });
29
+ },
30
+ async runScript(scriptPath, scriptArgs = [], options = {}) {
31
+ assert(scriptPath, "Script path is required");
32
+ assert(fs.existsSync(scriptPath), `Script does not exist: ${scriptPath}`);
33
+ return await logger.trace("python.runScript()", async (span) => {
34
+ span.setAttribute("scriptPath", scriptPath);
35
+ const result = await x(process.env.PYTHON_BIN_PATH || "python", [scriptPath, ...scriptArgs], {
36
+ ...options,
37
+ throwOnError: false,
38
+ });
39
+ if (result.exitCode) {
40
+ span.setAttribute("exitCode", result.exitCode);
41
+ }
42
+ if (result.exitCode !== 0) {
43
+ throw new Error(`${scriptPath} ${scriptArgs.join(" ")} exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
44
+ }
45
+ return result;
46
+ }, {
47
+ attributes: {
48
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
49
+ scriptPath,
50
+ args: scriptArgs.join(" "),
51
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
52
+ },
53
+ });
54
+ },
55
+ async runInline(scriptContent, options = {}) {
56
+ assert(scriptContent, "Script content is required");
57
+ return await logger.trace("python.runInline()", async (span) => {
58
+ span.setAttribute("contentLength", scriptContent.length);
59
+ // Using the withTempFile utility to handle the temporary file
60
+ return await withTempFile(`script_${Date.now()}.py`, async (tempFilePath) => {
61
+ span.setAttribute("tempFilePath", tempFilePath);
62
+ const pythonBin = process.env.PYTHON_BIN_PATH || "python";
63
+ const result = await x(pythonBin, [tempFilePath], {
64
+ ...options,
65
+ throwOnError: false,
66
+ });
67
+ if (result.exitCode) {
68
+ span.setAttribute("exitCode", result.exitCode);
69
+ }
70
+ if (result.exitCode !== 0) {
71
+ throw new Error(`Inline script exited with a non-zero code ${result.exitCode}:\n${result.stderr}`);
72
+ }
73
+ return result;
74
+ }, scriptContent);
75
+ }, {
76
+ attributes: {
77
+ pythonBin: process.env.PYTHON_BIN_PATH || "python",
78
+ contentPreview: scriptContent.substring(0, 100) + (scriptContent.length > 100 ? "..." : ""),
79
+ [SemanticInternalAttributes.STYLE_ICON]: "brand-python",
80
+ },
81
+ });
82
+ },
83
+ };
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src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,EAAE,CAAC;gBAC7E,CAAC,0BAA0B,CAAC,UAAU,CAAC,EAAE,cAAc;aACxD;SACF,CACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
3
+ * @param filename The filename to use for the temporary file
4
+ * @param callback Function that receives the path to the temporary file
5
+ * @param content Optional content to write to the file
6
+ * @returns Whatever the callback returns
7
+ */
8
+ export declare function withTempFile<T>(filename: string, callback: (filePath: string) => Promise<T>, content?: string | Buffer): Promise<T>;
@@ -0,0 +1,26 @@
1
+ import { mkdtemp, writeFile, rm } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ /**
5
+ * Creates a temporary file with a custom filename, passes it to the callback function, and ensures cleanup
6
+ * @param filename The filename to use for the temporary file
7
+ * @param callback Function that receives the path to the temporary file
8
+ * @param content Optional content to write to the file
9
+ * @returns Whatever the callback returns
10
+ */
11
+ export async function withTempFile(filename, callback, content = "") {
12
+ // Create temporary directory with random suffix
13
+ const tempDir = await mkdtemp(join(tmpdir(), "app-"));
14
+ const tempFile = join(tempDir, filename);
15
+ try {
16
+ // Write to the temporary file with appropriate permissions
17
+ await writeFile(tempFile, content, { mode: 0o600 });
18
+ // Use the file
19
+ return await callback(tempFile);
20
+ }
21
+ finally {
22
+ // Clean up
23
+ await rm(tempDir, { recursive: true, force: true });
24
+ }
25
+ }
26
+ //# sourceMappingURL=tempFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tempFiles.js","sourceRoot":"","sources":["../../../src/utils/tempFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,QAA0C,EAC1C,UAA2B,EAAE;IAE7B,gDAAgD;IAChD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzC,IAAI,CAAC;QACH,2DAA2D;QAC3D,MAAM,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACpD,eAAe;QACf,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;YAAS,CAAC;QACT,WAAW;QACX,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@trigger.dev/python",
3
+ "version": "0.0.0-prerelease-20250226191317",
4
+ "description": "Python runtime and build extension for Trigger.dev",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/triggerdotdev/trigger.dev",
12
+ "directory": "packages/python"
13
+ },
14
+ "type": "module",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "tshy": {
19
+ "selfLink": false,
20
+ "main": true,
21
+ "module": true,
22
+ "project": "./tsconfig.src.json",
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": "./src/index.ts",
26
+ "./extension": "./src/extension.ts"
27
+ },
28
+ "sourceDialects": [
29
+ "@triggerdotdev/source"
30
+ ]
31
+ },
32
+ "typesVersions": {
33
+ "*": {
34
+ "extension": [
35
+ "dist/commonjs/extension.d.ts"
36
+ ]
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "@trigger.dev/core": "0.0.0-prerelease-20250226191317",
41
+ "tinyexec": "^0.3.2"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "20.14.14",
45
+ "rimraf": "6.0.1",
46
+ "tshy": "^3.0.2",
47
+ "typescript": "^5.5.4",
48
+ "tsx": "4.17.0",
49
+ "esbuild": "^0.23.0",
50
+ "@arethetypeswrong/cli": "^0.15.4",
51
+ "@trigger.dev/build": "0.0.0-prerelease-20250226191317",
52
+ "@trigger.dev/sdk": "0.0.0-prerelease-20250226191317"
53
+ },
54
+ "peerDependencies": {
55
+ "@trigger.dev/sdk": "0.0.0-prerelease-20250226191317",
56
+ "@trigger.dev/build": "0.0.0-prerelease-20250226191317"
57
+ },
58
+ "engines": {
59
+ "node": ">=18.20.0"
60
+ },
61
+ "exports": {
62
+ "./package.json": "./package.json",
63
+ ".": {
64
+ "import": {
65
+ "@triggerdotdev/source": "./src/index.ts",
66
+ "types": "./dist/esm/index.d.ts",
67
+ "default": "./dist/esm/index.js"
68
+ },
69
+ "require": {
70
+ "types": "./dist/commonjs/index.d.ts",
71
+ "default": "./dist/commonjs/index.js"
72
+ }
73
+ },
74
+ "./extension": {
75
+ "import": {
76
+ "@triggerdotdev/source": "./src/extension.ts",
77
+ "types": "./dist/esm/extension.d.ts",
78
+ "default": "./dist/esm/extension.js"
79
+ },
80
+ "require": {
81
+ "types": "./dist/commonjs/extension.d.ts",
82
+ "default": "./dist/commonjs/extension.js"
83
+ }
84
+ }
85
+ },
86
+ "main": "./dist/commonjs/index.js",
87
+ "types": "./dist/commonjs/index.d.ts",
88
+ "module": "./dist/esm/index.js",
89
+ "scripts": {
90
+ "clean": "rimraf dist",
91
+ "build": "tshy && pnpm run update-version",
92
+ "dev": "tshy --watch",
93
+ "typecheck": "tsc --noEmit -p tsconfig.src.json",
94
+ "update-version": "tsx ../../scripts/updateVersion.ts",
95
+ "check-exports": "attw --pack ."
96
+ }
97
+ }